我有一张我正在处理的收据,它对我来说算数。我需要将结果显示为美元值。Onchange在小数点后添加2位数
我的HTML:
<input type="text" name="copy1" id="copy1" size="4" maxlength="10" onchange="calculate(this.value)">
<input type="text" name="copycosts" id="copycosts" size="4" VALUE=""/>
我的javascript:
<script type="text/javascript">
function calculate(){
var copy1value = parseFloat(document.getElementById("copy1").value, 10);
document.getElementById("copycosts").value = copy1value * 0.50;
}
</script>
如何添加2位小数乘法完成后?例如13 * 0.50 = 6.5 - 我想说它是6.50。
在此先感谢。
[parse float with two decimal places]的可能重复(http://stackoverflow.com/questions/4435170/parse-float-with-two-decimal-places) –