Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

format getting rounded off by a large amount using Intl.NumberFormat

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 is getting rounded off by a large amount here.
I want the above printed ₹89.73L

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

You have to use the minimumFractionDigits and maximumFractionDigits options to customize behaviour for decimal places.

Note that it will still get rounded.

For example:

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
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading