How to deal with Number precision in Actionscript?

后端 未结 14 1254
自闭症患者
自闭症患者 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:02

    Surprisingly the round function in MS Excel gives us different values then you have presented above. For example in Excel

    Round(143,355;2) = 143,36

    So my workaround for Excel round is like:

    public function setPrecision(number:Number, precision:int):Number {
    precision = Math.pow(10, precision);
    
    const excelFactor : Number = 0.00000001;
    
    number += excelFactor;
    
    return (Math.round(number * precision)/precision);
    }
    

提交回复
热议问题