向上舍入和向下舍入账单金额

编程入门 行业动态 更新时间:2024-10-24 14:25:19
本文介绍了向上舍入和向下舍入账单金额的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

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

更多推荐

向上舍入和向下舍入账单金额

本文发布于:2023-10-16 05:29:32,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1496637.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:账单   金额

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!