我在获取小数点后的数字时遇到问题.我需要数字来做 if else 语句.
这是一个例子:
31.30 = 31.3031.31 = 31.3031.32 = 31.3031.33 = 31.3531.34 = 31.3531.35 = 31.3531.36 = 31.3531.37 = 31.3531.38 = 31.4031.39 = 31.30所以,我需要得到小数点后的第二位数字.然后,我可以使用数字来做 if else 语句.这个四舍五入问题正在马来西亚发生.
解决方案像这样的方法可能适用于四舍五入到最接近的 5 美分,但您可能需要格式化输出以在小数点:
var origVal = 31.34;var roundedVal = Math.round(origVal*20)/20;这会给你 31.35,即四舍五入到最接近的镍.
这似乎比获取数字并执行 if/else 更直接一些.
I'm facing a problem to get the digit of a number after decimal point. I need the digit to do if else statement.
Here is an example:
31.30 = 31.30 31.31 = 31.30 31.32 = 31.30 31.33 = 31.35 31.34 = 31.35 31.35 = 31.35 31.36 = 31.35 31.37 = 31.35 31.38 = 31.40 31.39 = 31.30So, I need to get the second digit after decimal point. Then, i can use the digit to do if else statement. This rounding issue is happening in Malaysia.
解决方案Something like this might work for doing the rounding to the nearest 5 cents, although then you may need to format the output to have the proper number of digits past the decimal point:
var origVal = 31.34; var roundedVal = Math.round(origVal*20)/20;Which would give you 31.35, i.e., rounded to the nearest nickel.
This seems a little more direct than getting the digit and doing an if/else.
更多推荐
向上舍入和向下舍入账单金额
发布评论