将JavaScript字符串变量转换为十进制/货币 [英] convert a JavaScript string variable to decimal/money
本文介绍了将JavaScript字符串变量转换为十进制/货币的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
如何将JavaScript字符串变量转换为十进制?
How can we convert a JavaScript string variable to decimal?
是否存在诸如以下功能:
Is there a function such as:
parseInt(document.getElementById(amtid4).innerHTML)
推荐答案
是- parpFloat
。
parseFloat(document.getElementById(amtid4).innerHTML);
用于格式化数字,请使用 toFixed
:
For formatting numbers, use toFixed
:
var num = parseFloat(document.getElementById(amtid4).innerHTML).toFixed(2);
num
现在是一个带有数字的字符串格式为小数点后两位。
num
is now a string with the number formatted with two decimal places.
这篇关于将JavaScript字符串变量转换为十进制/货币的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文