使用 JavaScript 將數字轉換為印度貨幣


假設我們有一個數字,並且需要編寫一個 JavaScript 函式,該函式接受一個數字並返回其等值的印度貨幣。

toCurrency(1000) --> ₹4,000.00
toCurrency(129943) --> ₹1,49,419.00
toCurrency(76768798) --> ₹9,23,41,894.00

示例

程式碼如下 −

const num1 = 1000;
const num2 = 129943;
const num3 = 76768798;
const toIndianCurrency = (num) => {
   const curr = num.toLocaleString('en-IN', {
      style: 'currency',
      currency: 'INR'
   });
return curr;
};
console.log(toIndianCurrency(num1));
console.log(toIndianCurrency(num2));
console.log(toIndianCurrency(num3));

輸出

控制檯中的輸出為 −

₹1,000.00
₹1,29,943.00
₹7,67,68,798.00

更新於:20-Nov-2020

2000+ 次瀏覽量

開始你的 職業生涯

完成課程獲取認證

開始
廣告
© . All rights reserved.