Link to home
Start Free TrialLog in
Avatar of Steve Hougom
Steve HougomFlag for United States of America

asked on

Problem with angular currency pipe

I am using the angular currency pipe and it keeps formatting my input incorrectly.
For example I enter 12303 and its formatting it as $12,303.00 when i really wanted 123.03

Here is my line of code in typescript:  this.formattedAmount = this.currencyPipe.transform(temp, 'USD');
Hope someone can help.
Avatar of leakim971
leakim971
Flag of Guadeloupe image

this.formattedAmount = temp / 100;

Open in new window


ASKER CERTIFIED SOLUTION
Avatar of leakim971
leakim971
Flag of Guadeloupe image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
If you don't want the currency in the output why are you using the Currency pipe?
If your issue is that you are giving it cents and it is assuming you are giving it dollars then the answer is - don't give it cents.
Also interested to know why you are doing this in code - the currency pipe produces a string typically for output and is usually used in the view
{{myPrice | currency:'USD'}}

Open in new window

If you want to convert from cents then
{{myPrice / 100 | currency:'USD'}}

Open in new window


You have accepted an answer that is non-angular - while you can do it this way, Angular provides specific mechanisms for working with currencies. You should consider using those.

@Julian,
he said :
when i really wanted 123.03
@leakim

<span>{{currencyValue | currency:" "}}</span>

Open in new window

> 123.56