通过 .toString() 的数字格式 [关闭]
Posted
技术标签:
【中文标题】通过 .toString() 的数字格式 [关闭]【英文标题】:number format through .toString() [closed] 【发布时间】:2013-12-10 04:56:05 【问题描述】:新手问题:如何将 numberWithCommas 传递给我的值,以便我的数字格式正确?代码对我来说太复杂了。它正在工作,我只需要格式化数字。谢谢!
<script type="text/javascript">
function numberWithCommas(x)
return x.toString().replace(/\B(?=(\d3)+(?!\d))/g, ",");
if(!localStorage.Val1)
localStorage.Val1 = 1412015;
localStorage.Val2 = 20000;
localStorage.Val3 = 20000;
setInterval( function()
var popcounter = document.getElementById('pop');
var ethanolcounter = document.getElementById('ethanol');
var meatlcounter = document.getElementById('meat');
localStorage.Val1 = parseInt(localStorage.Val1,10)+1;
localStorage.Val2 = parseInt(localStorage.Val2,10)+1000;
localStorage.Val3 = parseInt(localStorage.Val3,10)+1000;
popcounter.innerhtml = localStorage.Val1,10;
ethanolcounter.innerHTML = localStorage.Val2;
meatlcounter.innerHTML = localStorage.Val3;
,1000);
</script>
【问题讨论】:
【参考方案1】:您是在问如何调用JavaScript function?好吧,假设您的功能正常工作:
popcounter.innerHTML=numberWithCommas(localStorage.Val1)
//repeat for Val2 and Val3
【讨论】:
以上是关于通过 .toString() 的数字格式 [关闭]的主要内容,如果未能解决你的问题,请参考以下文章
如何在 decimal.ToString() 中传递两种不同的数字格式 [重复]