我们如何将 JavaScript 字符串变量转换为十进制?
有没有这样的函数:
parseInt(document.getElementById(amtid4).innerHTML)
最佳答案
是——parseFloat
.
parseFloat(document.getElementById(amtid4).innerHTML);
要格式化 数字,请使用 toFixed
:
var num = parseFloat(document.getElementById(amtid4).innerHTML).toFixed(2);
num
现在是一个字符串,数字格式为两位小数。
关于javascript - 将 JavaScript 字符串变量转换为小数/货币,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/6095795/