Handling Currency for different locales in Javascript [closed]
I have a use case of adding or deleting certain items in a widget and correspondingly adding or subtracting prices in the total amount.
But while trying to handle this addition/subtraction in javascript i am facing issues for e.g
if the price is in the form of 1,50,000 or its like 1.50,000 (europe regions which treat comma as decimal).
So is there a way that i can generically handle these? Any service or libraries?
javascript regex locale
closed as too broad by Wiktor Stribiżew, mplungjan, RobG, Owen Pauling, greg-449 Nov 22 '18 at 10:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
add a comment |
I have a use case of adding or deleting certain items in a widget and correspondingly adding or subtracting prices in the total amount.
But while trying to handle this addition/subtraction in javascript i am facing issues for e.g
if the price is in the form of 1,50,000 or its like 1.50,000 (europe regions which treat comma as decimal).
So is there a way that i can generically handle these? Any service or libraries?
javascript regex locale
closed as too broad by Wiktor Stribiżew, mplungjan, RobG, Owen Pauling, greg-449 Nov 22 '18 at 10:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06
add a comment |
I have a use case of adding or deleting certain items in a widget and correspondingly adding or subtracting prices in the total amount.
But while trying to handle this addition/subtraction in javascript i am facing issues for e.g
if the price is in the form of 1,50,000 or its like 1.50,000 (europe regions which treat comma as decimal).
So is there a way that i can generically handle these? Any service or libraries?
javascript regex locale
I have a use case of adding or deleting certain items in a widget and correspondingly adding or subtracting prices in the total amount.
But while trying to handle this addition/subtraction in javascript i am facing issues for e.g
if the price is in the form of 1,50,000 or its like 1.50,000 (europe regions which treat comma as decimal).
So is there a way that i can generically handle these? Any service or libraries?
javascript regex locale
javascript regex locale
edited Nov 22 '18 at 9:03
khelwood
31.5k74364
31.5k74364
asked Nov 22 '18 at 8:50
Gaurav SetiaGaurav Setia
365
365
closed as too broad by Wiktor Stribiżew, mplungjan, RobG, Owen Pauling, greg-449 Nov 22 '18 at 10:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
closed as too broad by Wiktor Stribiżew, mplungjan, RobG, Owen Pauling, greg-449 Nov 22 '18 at 10:20
Please edit the question to limit it to a specific problem with enough detail to identify an adequate answer. Avoid asking multiple distinct questions at once. See the How to Ask page for help clarifying this question. If this question can be reworded to fit the rules in the help center, please edit the question.
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06
add a comment |
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06
add a comment |
1 Answer
1
active
oldest
votes
You can use javascript's Internationalisation function - Intl.NumberFormat()
to which you can pass locale
and currency
to format the number.
Find more information here -
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
add a comment |
1 Answer
1
active
oldest
votes
1 Answer
1
active
oldest
votes
active
oldest
votes
active
oldest
votes
You can use javascript's Internationalisation function - Intl.NumberFormat()
to which you can pass locale
and currency
to format the number.
Find more information here -
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
add a comment |
You can use javascript's Internationalisation function - Intl.NumberFormat()
to which you can pass locale
and currency
to format the number.
Find more information here -
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
add a comment |
You can use javascript's Internationalisation function - Intl.NumberFormat()
to which you can pass locale
and currency
to format the number.
Find more information here -
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
You can use javascript's Internationalisation function - Intl.NumberFormat()
to which you can pass locale
and currency
to format the number.
Find more information here -
https://developer.mozilla.org/enUS/docs/Web/JavaScript/Reference/Global_Objects/NumberFormat
answered Nov 22 '18 at 9:03
Rishikesh DhokareRishikesh Dhokare
2,3441427
2,3441427
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
add a comment |
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
That doesn't help with "is there a way that i can generically handle these", the issue being how does the OP determine the language to pass to the Intl formatter (noting that navigator.language is unreliable)?
– RobG
Nov 22 '18 at 9:17
add a comment |
Have you looked on NPM for packages? npmjs.com/search?q=money or npmjs.com/search?q=currency
– Yoram de Langen
Nov 22 '18 at 8:52
Questions asking us to recommend or find a book, tool, software library, tutorial or other off-site resource are off-topic for Stack Overflow as they tend to attract opinionated answers and spam. Instead, describe the problem and what has been done so far to solve it.
– mplungjan
Nov 22 '18 at 8:59
A simple solution, if you can guarantee that your prices will be whole numbers, is to simply strip all non-numeric characters from the input. (Also, don't use "1,50,000" as a generic display format for internationalization! That way of grouping digits is completely unheard of outside of India.)
– aaaaaa123456789
Nov 22 '18 at 10:06