本文介绍了Javascript十进制限制辅助的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我在下面有此代码.许多结果往往以小数点结尾,并且看起来很乱.我想将它们限制为一个,可能两个.我环顾四周,但恐怕不知道自己在做什么.
I have this code below. A lot of the results tend to end in decimals, and it looks quite messy. I want to restrict them to just one, possibly two. I''ve had a look around, but I''m afraid I have no idea what I''m doing.
physical age is <script type="text/javascript">
x=(231-{INPUT})*2/3; // Change the value of the number here according to your IC year
document.write(x);
</script>.
推荐答案
x=(231-{INPUT})*2/3;
x= x.toFixed(2);
这会将x舍入到小数点后2位
This will round x to 2 decimal places
这篇关于Javascript十进制限制辅助的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!