Ballerina 函数限制浮点数中的小数点

Ballerina function to limit the decimal points in a float

我想限制浮点值的小数位数,我不想在 Ballerina 中为此 rather format it. Is there a specific method like JavaScript toFixed()

我正在使用 Ballerina 0.990.2。

我想你要找的是io:sprintf()

例如 -

float f = 123.4567;
// This will format the floating point number to 2 decimal points.
io:println(io:sprintf("%.2f", f)); 

有关 sprintf 函数的更多信息,请访问 https://ballerina.io/learn/api-docs/ballerina/io.html#sprintf