1

So I have this usecase where I need to format currency inputs. For formating we are using AutoNumeric.js which is working fine.

What I need is to store value with default format which is sent to backend on submit and display formated currency in input (for instance, I want to display €10,000 to user and I should get value like 10000 to be sent to backend). Values should be stored in it's own variables.

What is standard Angular way of doing this?

Thanks!

2 Answers 2

1

You can use simple own converter:

let yourValue = '€10,000'
let res = '';
for (let index of yourValue) {
  if ( parseInt(el[index]) ) {
    res += el[index]
  }
}
console.log('your result = ', parseInt(numEl)) //your result = 10000
Sign up to request clarification or add additional context in comments.

1 Comment

Formatting was already taken care of, I had problem with separating formatted data from pure non-formatted data that is being sent to backend.
0

Angular already have a built-in currency pipe for it, all you need to play around it.

money = 10000; // backend value stored in DB

<!--display output in template '€10,000'-->
<div>{{ money | currency:'EUR':'symbol':'1.0'}}</div>

2 Comments

Thanks for your answer but currency pipe acted weird on inputs (I guess I was triggering it wrong and formatting was weird). But we already had solution for formatting. My problem was separating variables so that we have one for displaying data in input and another non-formatted variable for backend. Inputs were separated in it's own component so this issued is solved now :D
@Skafec glad to hear issue resolved, if you fee this answer somehow address the purpose you can accept the answer that could help others. Thanks

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.