JavaScript culture sensitive currency formatting
Asked Answered
W

4

7

How can i format currency related data in a manner that is culture aware in JavaScript?

Won answered 9/9, 2008 at 10:40 Comment(0)
H
-4

There is the Number.localeFormat() function, but I'm not sure it's what you're after.

http://msdn.microsoft.com/en-gb/library/bb310813.aspx

Homopterous answered 9/9, 2008 at 11:48 Comment(1)
this is an ASP.NET extension function, not native JSVestibule
B
3

So I know this is an old question, but incase anyone else shows up looking for similar answers, in modern JavaScript you can use

new Intl.NumberFormat('de-DE', { style: 'currency', currency: 'EUR' }).format(number)

For more info here is the reference doc.

https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Intl/NumberFormat

Bracteole answered 5/3, 2021 at 17:46 Comment(0)
M
2

Dojo has a currency formatter that's locale aware.

If you don't want to include Dojo in your project just for this function, then perhaps you can localize the currency in your back-end?

Make answered 9/9, 2008 at 10:47 Comment(1)
I believe the Dojo currecy formatting is based on XML data from the Unicode Common Locale Data Repository (unicode.org/cldr). While Dojo will do the hard work for you, if you don't want to use it you can get the raw data from there.Volitive
L
1

Number.toLocaleString (implemented in JavaScript 1.5, ECMAScript 3rd Edition)

var number = 3500;
console.log(number.toLocaleString()); /* Displays "3,500" in English locale */

Docs on MDN.

Latini answered 28/1, 2013 at 14:57 Comment(1)
This might not work in a node.js environment. you might need to load 'intl' and locale files.Buckhound
H
-4

There is the Number.localeFormat() function, but I'm not sure it's what you're after.

http://msdn.microsoft.com/en-gb/library/bb310813.aspx

Homopterous answered 9/9, 2008 at 11:48 Comment(1)
this is an ASP.NET extension function, not native JSVestibule

© 2022 - 2024 — McMap. All rights reserved.