如何在JavaScript中将.0附加到整数(300.0)而不转换为字符串?
var wholeNumber = 300.0;
var integer = 300;
console.log( wholeNumber ); //output 300
console.log( parseFloat(wholeNumber) ); //output 300
console.log( parseFloat(integer+".0") ); //output 300
我已经尝试了多种方法,但似乎不起作用,除非数字带有小数,例如300.1
答案 0 :(得分:0)
https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed
var a = 300;
console.log(a.toFixed(1));