'Javascript How To Format An Integer As A Currency String?
I have an integer stored as US cents, ie 1700 cents. How can I convert that to a string that is $17.00 using javascript? I have tried toFixed and Intl.NumberFormat but they return $1700?
Solution 1:[1]
You can use toLocaleString() function for this.
var cents = 1629;
var dollars = cents / 100;
dollars = dollars.toLocaleString("en-US", {style:"currency", currency:"USD"});
console.log(dollars);
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Sumit Sharma |
