使用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
热门推荐
10 春节红包祝福语大全简短
11 女儿要生了祝福语简短
12 买车新年祝福语简短创意
13 心媳妇生日祝福语简短
14 带猫的祝福语简短
15 祝福语简短情话高级英文
16 简短结婚的祝福语大全
17 佛学生日简短祝福语
18 拜年同事祝福语大全简短