例如Number.MAX_VALUE.toString()
是"1.7976931348623157e+308"
我希望没有e+308
,如何实现这个目标?
答案 0 :(得分:1)
你可以这样做:
var n = Number.MAX_VALUE.toString();
var parts = n.split("e+");
var first = parts[0].replace('.', "");
var zeroes = parseInt(parts[1], 10) - (first.length - 1);
for(var i = 0; i < zeroes; i++){ first += "0"; }
// => first === "179769313486231570000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000000"