Skip to content

Numbers

Integers

Integer numbers follow C-style format with support for decimal, binary (0b), octal (0o) and hex (0x) notations.

Integers can also be conveniently manipulated as bit-fields.

Floating-Point Numbers

Both decimal and scientific notations can be used to represent floating-point numbers.

Decimal Numbers

When rounding errors cannot be accepted, such as in financial calculations, use the decimal type, which is a fixed-precision floating-point number with no rounding errors.

Number Literals

_ separators can be added freely and are ignored within a number – except at the very beginning or right after a decimal point (.).

Sample Format
_123 improper separator
123_345, -42 decimal
0o07_76 octal
0xab_cd_ef hex
0b0101_1001 binary
123._456 improper separator
123_456.78_9 normal floating-point
-42. ending with decimal point
123_456_.789e-10 scientific notation
.456 missing leading 0
123.456e_10 improper separator
123.e-10 missing decimal 0

Floating-Point vs. Decimal

Decimal numbers represents a fixed-precision floating-point number which is popular with financial calculations and other usage scenarios where round-off errors are not acceptable.

Decimal numbers take up more space (16 bytes each) than a standard floating-point number (4-8 bytes) and is much slower in calculations due to the lack of CPU hardware support. Use it only when necessary.