[removed] Rounding Down in .5 Cases

前端 未结 4 2011
借酒劲吻你
借酒劲吻你 2020-12-19 05:08

I am in a situation where a JavaScript function produces numbers, such as 2.5. I want to have these point five numbers rounded down to 2, rather t

4条回答
  •  春和景丽
    2020-12-19 05:27

    Another way exists that is to use real numbers (instead of 0.2 use 20, 0.02 use 2, etc.), then add floatingPoints variable that will divide the result (in your case it's 2). As a result you can operate as Number/(10^floatingPoints). This solution is wide across Forex companies.

提交回复
热议问题