Monday, May 20, 2024
 Popular · Latest · Hot · Upcoming
164
rated 0 times [  170] [ 6]  / answers: 1 / hits: 35959  / 10 Years ago, mon, april 21, 2014, 12:00:00

So I was writing a small helper method to convert numbers into a valid money format ($xx,xxx.xx) using .toLocaleString(). Everything works as expected when using it inside Chrome, however it seems completely broken when using inside Node.js.



Example:



var n = 6000
console.log( n.toLocaleString('USD', {
style: 'currency',
currency: USD,
minimumFractionDigits : 2,
maximumFractionDigits : 2
}) );


If you run this in the browser, it prints $6,000.00. If you run this snippet inside of Node.js REPL or application, it returns 6000 as a String.



Guessing this is a bug with Node.js? Is there a work around you could do here?


More From » node.js

 Answers
11

Based on this issue it appears that it was decided that shipping node.js with internationalization would make it too large. You can npm install intl and require that, and it will replace toLocaleString with a version that works.


[#71366] Saturday, April 19, 2014, 10 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
davion

Total Points: 458
Total Questions: 109
Total Answers: 100

Location: Taiwan
Member since Mon, Sep 6, 2021
3 Years ago
;