-3
我试图打印一个有两位小数的数字,我需要将它作为千位分隔符。如何用javascript格式化数字(以Safari的方式工作)
我不能使用.toLocaleString()
,因为它不会在Safari工作...
这里是我的代码:
var currentTime;
if (localStorage['time']) {
currentTime = Number.parseFloat(localStorage['time']);
}
else {
currentTime = 0;
}
var container = document.getElementById('count');
setInterval(function() {
currentTime += .01;
container.innerHTML = currentTime.toFixed(2);
//container.innerHTML = currentTime.toLocaleString(undefined, {minimumFractionDigits: 2, maximumFractionDigits: 2});
localStorage['time'] = currentTime;
}, 100);
这里有一个关于这个常见问题的深入答案http://stackoverflow.com/a/149099/280842 – Filype
可能的重复[如何将数字格式化为JavaScript中的金钱?] (http://stackoverflow.com/questions/149055/how-can-i-format-numbers-as-money-in-javascript) – jmoerdyk