当我尝试将其舍入到小数点后一位时,我已经有了此功能,并且我已经阅读了许多有关此主题的信息,但似乎没有注册。
function myFunction() {
var testNumber = 399.894; // required output is 399.90 - correct
var testNumber = 389.894; // required outout is 389.90 - correct
var testNumber = 389.891; // required output is 390.90 - correct
var testNumber = 379.791 // required output is 379.80 - correct
var testNumber = 399.991 // required output is 400.00 - correct
var testNumber = 379.761 // required output is 379.77 - incorrect - shows 379.80
return Number(Math.round(testNumber+'e1')+'e-1');
}
var myNumbers = myFunction();
alert(myNumbers );
我认为确保将其四舍五入到下一分似乎很容易,
小提琴链接:http://jsfiddle.net/axd0y581/5/
希望这里有人可以替我哑巴
预先感谢
答案 0 :(得分:0)
答案 1 :(得分:0)
可能您可以尝试以下方法:Math.ceil(testNumber +'e2')/100