0

I have few values coming from server which are conceptually currencies but stored in the system as string like this 274,412.00. Also there won't always be trailing zeroes.

I need to convert those into numbers for some calculations. I can't use the currency pipe with that:

{{ myvalue | currency:'GBP')

How can I convert them?

Rory McCrossan
  • 331,213
  • 40
  • 305
  • 339
Sandeep Thomas
  • 4,303
  • 14
  • 61
  • 132
  • 1
    This is exactly why you do not store formatted numbers in the server side datastore. Store them as numeric values and only format them as needed when displayed in the UI. I'd suggest you fix the problem that way instead of hacking the formatted string back in to a numerical value. – Rory McCrossan May 15 '20 at 13:57
  • @RoryMcCrossan We are relying a third party API to get those values. We dont have any freedom over that data. We are always storing currency values as number – Sandeep Thomas May 15 '20 at 14:27
  • You can intercept the API response and parse the result as a number before sending it to the UI. Since you're using Angular, you can so this in your Service. PITA, but that's the cost of doing business with that third party API... – Heretic Monkey May 15 '20 at 14:44
  • Does this answer your question? [Javascript Thousand Separator / string format](https://stackoverflow.com/questions/3753483/javascript-thousand-separator-string-format) – jpf May 15 '20 at 19:37

0 Answers0