How to Format Numbers As A Currency String in Javascript

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…

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

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


Print Share Comment Cite Upload Translate Updates
APA

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/

MLA
" » How to Format Numbers As A Currency String in Javascript." Ariessa Norramli | Sciencx - Sunday February 21, 2021, https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/
HARVARD
Ariessa Norramli | Sciencx Sunday February 21, 2021 » How to Format Numbers As A Currency String in Javascript., viewed ,<https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/>
VANCOUVER
Ariessa Norramli | Sciencx - » How to Format Numbers As A Currency String in Javascript. [Internet]. [Accessed ]. Available from: https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/
CHICAGO
" » How to Format Numbers As A Currency String in Javascript." Ariessa Norramli | Sciencx - Accessed . https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/
IEEE
" » How to Format Numbers As A Currency String in Javascript." Ariessa Norramli | Sciencx [Online]. Available: https://www.scien.cx/2021/02/21/how-to-format-numbers-as-a-currency-string-in-javascript/. [Accessed: ]
rf:citation
» How to Format Numbers As A Currency String in Javascript | Ariessa Norramli | Sciencx | 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.

You must be logged in to translate posts. Please log in or register.