Numbers
Arbitrary-precision fixed-point decimal numbers.
Zaidlang has a single numberic type; arbitrary-precision fixed-point decimals. While most other languages contain representations for integers, floats, doubles, etc., we found that having just a single number type was easier to use even at the slight cost of performance.
Because Zaidlang uses an arbitrary-precision fixed-point decimal system, it is extremely accurate. Number values look like you expect from other languages:
Precision
Float point numbers (or any binary floating point type) can't represent fractional decimals (0.1
) precisely. When adding and subtracting them repeatedly will cause rounding errors.
For example, let's consider this code in Go:
You might expect it to print 10
, but it in fact prints 9.999999999999831
. This may not be so much of an issue, but if you were having to calculate with extreme precision (such as money), you could find yourself short a few dollars in some extreme cases.
If you were to run the same program above in Zaidlang, you'd find that the result does come out to exactly 10
:
Numbers in Zaidlang can only represent numbers with a maximum of 2^31 digits after the decimal point.
Scientific Notation
Numeric values can be represented in scientific notation by using e
. This returns a value multiplied by the specified power of 10
.
Methods
round()
round()
The round()
method rounds the given number to the nearest integer to the specified precision.
toString()
toString()
The toString()
method returns the given number as a string.
Last updated