How to deal with Number precision in Actionscript?

后端 未结 14 1246
自闭症患者
自闭症患者 2020-11-29 03:23

I have BigDecimal objects serialized with BlazeDS to Actionscript. Once they hit Actionscript as Number objects, they have values like:

140475.32 turns

14条回答
  •  日久生厌
    2020-11-29 04:06

    i've used Number.toFixed(precision) in ActionScript 3 to do this: http://livedocs.adobe.com/flex/3/langref/Number.html#toFixed%28%29

    it handles rounding properly and specifies the number of digits after the decimal to display - unlike Number.toPrecision() that limits the total number of digits to display regardless of the position of the decimal.

    var roundDown:Number = 1.434;                                             
    // will print 1.43                                                        
    trace(roundDown.toFixed(2));                                              
    
    var roundUp:Number = 1.436;                                               
    // will print 1.44                                                        
    trace(roundUp.toFixed(2));                                                
    

提交回复
热议问题