Swan Lake Beta3 is here.
import ballerina/io;

public function main() {
    float x = 1.0;

    int n = 5;

    // No implicit conversions between integers and floating point values are allowed.
    // You can use `<T>` for explicit conversions.
    float y = x + <float>n;

    io:println(y);
}

Floating Point Numbers

The float type is IEEE 64-bit binary floating point (same as double in Java) and supports the same arithmetic operators as int.

import ballerina/io;
public function main() {
    float x = 1.0;
    int n = 5;
    float y = x + <float>n;

No implicit conversions between integers and floating point values are allowed. You can use <T> for explicit conversions.

    io:println(y);
}
bal run floating_point_numbers.bal 
6.0
import ballerina/io;

public function main() {
    float x = 1.0;

    int n = 5;

    // No implicit conversions between integers and floating point values are allowed.
    // You can use `<T>` for explicit conversions.
    float y = x + <float>n;

    io:println(y);
}

Floating Point Numbers

The float type is IEEE 64-bit binary floating point (same as double in Java) and supports the same arithmetic operators as int.

import ballerina/io;
public function main() {
    float x = 1.0;
    int n = 5;
    float y = x + <float>n;

No implicit conversions between integers and floating point values are allowed. You can use <T> for explicit conversions.

    io:println(y);
}
bal run floating_point_numbers.bal 
6.0
Subscribe to the newsletter

In the creation of Ballerina, we were inspired by so many technologies. Thank you to all that have come before us (and forgive us if we missed one): Java, Go, C, C++, D, Rust, Haskell, Kotlin, Dart, TypeScript, JavaScript, Python, Perl, Flow, Swift, Elm, RelaxNG, NPM, Crates, Maven, Gradle, Kubernetes, Docker, Envoy, Markdown, GitHub and WSO2.

Cookie Policy

This website uses cookies so that we can provide you with the best user experience. Read our Cookie Policy to find out more.

If you wish to disable cookies you can do so from your browser.

I Understand