问题描述
||
我有此脚本正在格式化我的货币,但现在无法将我的值固定为0小数位,我是javascript的新手,所以有人可以解释在哪里和我要这样做吗?谢谢
function FormatNumberBy3(num,decpoint,sep) {
// check for missing parameters and use defaults if so
if (arguments.length == 2) {
sep = \",\";
}
if (arguments.length == 1) {
sep = \",\";
decpoint = \".\";
}
// need a string for operations
num = num.toString();
// separate the whole number and the fraction if possible
a = num.split(decpoint);
x = a[0]; // decimal
y = a[1]; // fraction
z = \"\";
if (typeof(x) != \"undefined\") {
// reverse the digits. regexp works from left to right.
for (i=x.length-1;i>=0;i--)
z += x.charAt(i);
// add seperators. but undo the trailing one,if there
z = z.replace(/(\\d{3})/g,\"$1\" + sep);
if (z.slice(-sep.length) == sep)
z = z.slice(0,-sep.length);
x = \"\";
// reverse again to get back the number
for (i=z.length-1;i>=0;i--)
x += z.charAt(i);
// add the fraction back in,if it was there
if (typeof(y) != \"undefined\" && y.length > 0)
x += decpoint + y;
}
return x;
}
解决方法
暂无找到可以解决该程序问题的有效方法,小编努力寻找整理中!
如果你已经找到好的解决方法,欢迎将解决方案带上本链接一起发送给小编。
小编邮箱:dio#foxmail.com (将#修改为@)