Handling Currency for different locales in Javascript [closed]












-1















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?










share|improve this 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
















-1















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?










share|improve this 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














-1












-1








-1








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?










share|improve this question
















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






share|improve this question















share|improve this question













share|improve this question




share|improve this question








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



















  • 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












1 Answer
1






active

oldest

votes


















2














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






share|improve this answer
























  • 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




















1 Answer
1






active

oldest

votes








1 Answer
1






active

oldest

votes









active

oldest

votes






active

oldest

votes









2














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






share|improve this answer
























  • 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


















2














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






share|improve this answer
























  • 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
















2












2








2







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






share|improve this answer













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







share|improve this answer












share|improve this answer



share|improve this answer










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





















  • 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







Popular posts from this blog

Can a sorcerer learn a 5th-level spell early by creating spell slots using the Font of Magic feature?

Does disintegrating a polymorphed enemy still kill it after the 2018 errata?

A Topological Invariant for $pi_3(U(n))$