Skafec
Skafec

Reputation: 49

Format and parse input values

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!

Upvotes: 1

Views: 330

Answers (2)

Kamran Khatti
Kamran Khatti

Reputation: 4137

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>

Upvotes: 0

andrew kot
andrew kot

Reputation: 175

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

Upvotes: 1

Related Questions