使用默认值格式化文本框以显示2个小数位

时间:2013-08-01 03:43:35

标签: javascript

我的页面中有文本框,我在其中显示默认值,值来自数据库并且有4个小数位但是我想只显示两个小数位,我尝试将格式#,## 0.00但是这个没有工作,下面的代码我正在创建文本框并分配默认值

<input type="text" name="tproj" id="{concat('txtboxAdjustment', position())}" value="{@proj}" style="font-size:10px;padding:0px;height:15px;width:90px;text-align:right;" onKeyPress="return validateKeyPress(this,event)" onkeyup="return validateKeyUp(this,event);" onblur="calculate_elect_total()" />

1 个答案:

答案 0 :(得分:0)

toFixed()将在javascript中为您提供帮助。但是我不确定如何在你的情况下添加它。

尝试以下

value = @proj.toFixed(2);  //Not sure in your case

编辑:示例代码:

var no = 22.333333;
alert(no.toFixed(2));  //returns 22.33