开发者

Why AS3 toFixed method returns a String?

开发者 https://www.devze.com 2023-03-25 17:08 出处:网络
Is there a开发者_如何学JAVAny (rational) reason why the toFixed method of AS3 Number class returns a String?The purpose of the toFixed and other such convenience methods on the Number class is to give

Is there a开发者_如何学JAVAny (rational) reason why the toFixed method of AS3 Number class returns a String?


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).

0

精彩评论

暂无评论...
验证码 换一张
取 消