使用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 送给学长毕业祝福语简短