如何在javascript中将整数类型转换为金额类型?
可能重复:如何在javascript中将整数类型转换为金额类型?,javascript,asp.net,Javascript,Asp.net,可能重复: 在JavaScript中,我访问了如下变量: amount= document.getElementById('<%= DataItemValue1.ClientID%>').firstChild.nodeValue; amount=document.getElementById(“”).firstChild.nodeValue; 现在,如果金额是10945,我希望它是$10945;如果1098为1098美元 如何在javascript中执行此操作并将其传递给标签
在JavaScript中,我访问了如下变量:
amount= document.getElementById('<%= DataItemValue1.ClientID%>').firstChild.nodeValue;
amount=document.getElementById(“”).firstChild.nodeValue;
现在,如果金额是10945
,我希望它是$10945
;如果1098
为1098美元
如何在javascript中执行此操作并将其传递给标签
非常感谢。使用此功能
function amount( value ) {
value = value.toString();
var o = '';
do {
var s = value.substr( -3 );
value = value.substr( 0, value.length - 3 );
o = (value.length?',':'')+s+o;
} while( value.length );
return '$'+o;
}
谢谢你,弗雷德里克,这真的很管用,一句话也没换。