Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Why AS3 toFixed method returns a String?

Is there any (rational) reason why the toFixed method of AS3 Number class returns a String?


1 Answers

The purpose of the toFixed and other such convenience methods on the Number class is to give you a humanly readable String representation of that Number. Its purpose is not to round it, as you seem to assume. There's Math.round() for real rounding operations.

An obvious use case would be a table or a spreadsheet where you would want all your numbers to be displayed in the same way (e.g. 1.25 - 6.10). That would make it easier for humans to scan the data and doesn't change the underlying Number (which in the example could be: 1.2567 - 6.1).

like image 132
RIAstar Avatar answered May 16 '26 20:05

RIAstar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!