我想將數字轉換爲數字格式。格式編號爲角錢格式
我已經試過這至今:http://plnkr.co/edit/lVJGXyuX0BMvB9QUL5zS?p=preview
function formatMoney(credits) {
console.log(credits+'credits');
var lastThree = credits.substring(credits.length-3);
// var lastThree = credits.slice(-2);
var otherNumbers = credits.substring(0,credits.length-3);
console.log(otherNumbers+'otherNumbers');
if(otherNumbers !== '')
lastThree = ',' + lastThree;
var res = otherNumbers.replace(/\B(?=(\d{2})+(?!\d))/g, ",") + lastThree;
return res;
}
function formatNumber(num) {
var n1, n2;
num = (Math.round(num * 100)/100) + '' || '';
n1 = num.split('.');
n2 = n1[1] || null;
n1 = n1[0].replace(/(\d)(?=(\d\d)+\d$)/g, ",");
num = n2 ? n1 + '.' + n2 : n1;
return num;
}
我想將數字轉換爲印度貨幣。
實施例:
1,000
10,000
1,00,000
10,00,000
,我與功能formatMoney()獲得的輸出:1,0,0,000
,我與功能formatNumber()獲得的輸出:1000和壓制後0,它變成NaN0
我在這裏做錯了什麼?
這已經回答。 http://stackoverflow.com/questions/16037165/displaying-a-number-in-indian-format-using-javascript 如果這不起作用,生病會很高興給它一個去。 – Conceptz
@Conceptz我可能是錯的,在這裏是相當新的,但我認爲這個問題是基於angularJS的不同的答案,給出了它如何被標記 –
@Conceptz:我試了相同的代碼,不適合我。我在這裏做錯了什麼? – nirvair