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
您必须使用
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