向上舍入和向下舍入账单金额 [英] Rounding up and rounding down bill amount

查看:55
本文介绍了向上舍入和向下舍入账单金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在获取小数点后的数字时遇到问题.我需要数字来做 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.30   

So, 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.

这篇关于向上舍入和向下舍入账单金额的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆