import ballerina/io;
public function main() {
    int i = 10;
    io:println(i);
    float f = 20.0;
    io:println(f);
    float nanVal = 0.0/0.0;
    io:println(nanVal.isNaN());
    float infiniteVal = 12.0/0.0;
    io:println(infiniteVal.isInfinite());
    float finiteVal = 6.0/3.0;
    io:println(finiteVal.isFinite());
    decimal d = 27.5;
    io:println(d);
    byte c = 23;
    io:println(c);
    string s = "Ballerina";
    io:println(s);
    boolean b = true;
    io:println(b);
    () n = ();
    io:println(n);
    json j = null;
    io:println(j);
}

Values

Ballerina programs operate on a universe of values, and each value belongs to only one basic type such as int, boolean, map, record, function, etc. There are three kinds of values corresponding to three kinds of basic types. They are simple values (e.g., int, string, boolean), structured values (e.g., record, map, array), and behavioral values (e.g., function, object). Simple values belong to one of the simple basic types, namely nil, boolean, int, float, decimal and string.

import ballerina/io;
public function main() {

The types int, float, decimal, string, boolean, byte and nil are called simple basic types because they are basic types with only simple values. Simple values are always immutable.

    int i = 10;
    io:println(i);

The int type represents the set of 64-bit signed integers.

    float f = 20.0;
    io:println(f);

The float type represents the set of double precision IEEE 754 floating point numbers.

    float nanVal = 0.0/0.0;
    io:println(nanVal.isNaN());

isNaN(), isInfinite() and isFinite() builtin functions are supported for the float type. isNaN() will return true if the float value is neither finite nor infinite.

    float infiniteVal = 12.0/0.0;
    io:println(infiniteVal.isInfinite());

isInfinite() will return true if the float value is neither NaN nor finite.

    float finiteVal = 6.0/3.0;
    io:println(finiteVal.isFinite());

isFinite() will return true if the float value is neither NaN nor infinite.

    decimal d = 27.5;
    io:println(d);

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

    byte c = 23;
    io:println(c);

The byte type represents the set of 8-bit unsigned integers.

    string s = "Ballerina";
    io:println(s);

The string type represents the set of sequences of Unicode code points.

    boolean b = true;
    io:println(b);

The boolean type has only two values, true and false.

    () n = ();
    io:println(n);

The nil type has a single value and is used to represent the absence of any other value. Both, the nil type and the nil value are written as ().

    json j = null;
    io:println(j);
}

Another representation for the nil value is the null literal. However, the use of the null literal in only allowed in JSON contexts.

# To run this sample, navigate to the directory that contains the
# `.bal` file and execute the `ballerina run` command.
$ ballerina run values.bal
10
20.0
true
true
true
27.5
23
Ballerina
true