使用 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
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 程序设计
C++
C#
MongoDB
MySQL
Javascript
PHP