格式使用 Intl.NumberFormat [重复]

问题描述 投票:0回答:1
let just_the_number = '8973565';

const just_the_number_formatted = Intl.NumberFormat("en-IN", { minimumFractionDigits: 0 }).format(parseFloat(just_the_number));
console.log(just_the_number_formatted)

let formatted_amount = new Intl.NumberFormat("en-IN", {
      style: "currency",
      currency: "INR",
      notation: "compact",
      compactDisplay: "long",
    }).format(just_the_number);

console.log(formatted_amount) // prints ₹90L

formatted_amount 在这里被四舍五入很大。 我想要上面打印的 £89.73L

javascript format decimal currency
1个回答
0
投票

您必须使用

minimumFractionDigits
maximumFractionDigits
选项来自定义小数位的行为。

请注意,它仍然会被舍入。

例如:

let just_the_number = '8973565';

let formatted_amount = new Intl.NumberFormat("en-IN", {
      style: "currency",
      currency: "INR",
      notation: "compact",
      compactDisplay: "long",
      minimumFractionDigits: 2,
      maximumFractionDigits: 2,
    }).format(just_the_number);

console.log(formatted_amount) // prints ₹89.74L
© www.soinside.com 2019 - 2024. All rights reserved.