import ballerina/io;

// The `decimal` type represents the set of 128-bits IEEE 754R decimal floating point numbers.
decimal nanos = 1d/1000000000d;

function floatSurprise() {
    float f = 100.10 - 0.01;
    io:println(f);
}

public function main() {
    floatSurprise();
    io:println(nanos);

    // Numeric literals can use the `d` suffix for them to be interpreted as `decimal` values
    // (similarly, the `f` suffix can be used for `float`).
    var d = 12345d;
    io:println(d is decimal);
}

Decimal type

The decimal type is the third numeric type. It works like int and float types. It is a separate basic type and belongs to the anydata type. There is no implicit conversions between decimal and other numeric types. It can represent decimal fractions exactly and it preserves precision. The decimal type does not include infinity, NaN, or negative zero. It supports floating-point precision to 34 decimal digits.

import ballerina/io;
decimal nanos = 1d/1000000000d;

The decimal type represents the set of 128-bits IEEE 754R decimal floating point numbers.

function floatSurprise() {
    float f = 100.10 - 0.01;
    io:println(f);
}
public function main() {
    floatSurprise();
    io:println(nanos);
    var d = 12345d;
    io:println(d is decimal);
}

Numeric literals can use the d suffix for them to be interpreted as decimal values (similarly, the f suffix can be used for float).

bal run decimal_type.bal
100.08999999999999
1E-9
true