This is not exactly currency arithmetic problem but really just regular arithmetic issue. Is there an API which handles decimal arithmetic (compare, subtract and addition) in JavaScript? Which shall also handle locale/language-specific decimal format. Any pointers are appreciated. I am also ready to write the API, would be great if you guys has some suggestion on approach.
Asked
Active
Viewed 488 times
3
-
1also see http://stackoverflow.com/questions/744099/javascript-bigdecimal-library – Marco Mariani Feb 16 '12 at 13:23
-
When I think of decimal arithmetic http://speleotrove.com/decimal/ comes to mind. – Dan D. Feb 16 '12 at 13:23
3 Answers
2
After quick scan, I discovered that among their many APIs, Google provide a JSON based currency converter. A request can be made from a URL such as: http://www.google.com/ig/calculator?hl=en&q=1.4GBP=?USD
And the return format will be a JSON string such as:
{lhs: "1.4 British pounds",rhs: "2.19464 U.S. dollars",error: "",icc: true}
This can be evaluated in Javascript with the eval function, or more safely, something like the
jQuery.parseJSON()
It's far from elegant, but it might help.

Dan Prince
- 29,491
- 13
- 89
- 120
-
thanks a lot. But conversion not my intention I have edited the question. my main problem is to compare, subtract and addition. – yadab Feb 16 '12 at 13:26
2
You can also use money.js
if dealing with currencies and their conversion. Examples in the linked site.

Martin Spa
- 1,494
- 1
- 24
- 44
-
-
1No, but here's how to do it (tl;dr is that always use integers for operations): http://stackoverflow.com/a/2556360/228692 – Martin Spa Feb 16 '12 at 13:57
1
Edit: I realise this doesn't fully answer your question, but you may find it useful for formatting if you weren't already aware of it.

daniel
- 1,148
- 1
- 13
- 20