There is an issue with ‘Std. parseFloat’
I want to always keep ‘2 decimal places’,
But ‘Std. parseFloat’ removed my other decimal point!
.
I have written a function that retains my 2 decimal points,
The conversion of ‘Std. parseFloat’ to numbers has removed decimals ..
function toFixed(num:Float):String {
var rounded = Math.fround(num * 100) / 100;
var str = Std.string(rounded);
var parts = str.split(".");
if (parts.length < 2) {
return str + ".00";
}
while (parts[1].length < 2) {
parts[1] += "0";
}
return parts[0] + "." + parts[1].substr(0, 2);
}
.
Sorry, I’ve always been mistaken about the type.
.
Because I used to use ‘as3’, I often used ‘toFixed’ to keep 2 as a decimal point
.
But when I used ‘openfl’, I found that there was no built-in method to achieve my effect, so I have been seeking solutions
.