Luiz Ricardo Cardoso
Luiz Ricardo Cardoso

Reputation: 1624

How to convert string to double in angular

I am using a payments API in my application and am getting the invoice value with type number

signature.invoice.amount: 10500 (Number)

I tried to use currency pipe {{ signature.invoice.amount | currency: 'BRL': true}} and the transformed value is: $ 10,500.00.

But the transformed value should be $ 105.00 ... how do I get the number of the amount received to a monetary value in 'BRL' with a return of the number type?

Upvotes: 1

Views: 1458

Answers (1)

xavdid
xavdid

Reputation: 5264

Since $105.00 is 10,500 cents, you want to convert it to dollars before transforming it:

{{ signature.invoice.amount / 100 | currency: 'BRL': true}}

Good job storing currency as cents though! That's the way to do it to save yourself errors down the line.

Upvotes: 1

Related Questions