This content originally appeared on CodeSource.io and was authored by Ariessa Norramli
In this article, you will learn how to format numbers as a currency string in Javascript.
Let’s say you have a number variable ‘a’ with value 12345.60
var a = 12345.60;
In order to format numbers as a currency, you can use the Intl.NumberFormat()
method. In this example, you will be formatting a number into a currency of type USD.
var a = 12345.60;
var options = { style: 'currency', currency: 'USD' };
console.log(new Intl.NumberFormat('en-US', options).format(a));
// => "$12,345.60"
Note: The Intl.NumberFormat()
method functions by formatting a number according to the locale and formatting options.
The post How to Format Numbers As A Currency String in Javascript appeared first on CodeSource.io.
This content originally appeared on CodeSource.io and was authored by Ariessa Norramli

Ariessa Norramli | Sciencx (2021-02-21T10:15:32+00:00) How to Format Numbers As A Currency String in Javascript. Retrieved from https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/
Please log in to upload a file.
There are no updates yet.
Click the Upload button above to add an update.