Keyboard shortcuts

Press ← or → to navigate between chapters

Press S or / to search in the book

Press ? to show this help

Press Esc to hide this help

Conversion and Output

String conversions

MethodExample output
String(x)"12345"
repr(x)'BigInt("12345")'
x.to_string_with_separators("_")"1_234_567"
x.to_string_with_separators(",")"1,234,567"
x.to_hex_string()"0x1A2B3C"
x.to_binary_string()"0b110101"
x.to_string(line_width=20)Multi-line output
x.to_chinese()"十五"

Numeric conversions

MethodDescription
Int(x)Convert to Int (raises if exceeds 64-bit range)
Float64(x)Convert to Float64 (may lose precision)
x.to_biguint()Convert the magnitude to BigUInt (base-10^18)
var x = BInt("123456789012345678901234567890")
print(x.to_string_with_separators())  # 123_456_789_012_345_678_901_234_567_890
print(x.to_hex_string())              # 0x...

to_chinese() writes the number in Chinese numerals; see Chinese Numerals for the reading rules and the available styles.

print(BInt(15).to_chinese())          # 十五
print(BInt("123456789").to_chinese()) # 一亿二千三百四十五万六千七百八十九