3

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.

yadab
  • 2,063
  • 1
  • 16
  • 24

3 Answers3

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.

http://josscrowcroft.github.com/money.js/

Martin Spa
  • 1,494
  • 1
  • 24
  • 44
1

Try Number.toLocaleString().

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