Dollars to Cents in AngularJS for Stripe Checkout

1.4k views Asked by At

So I have a value that is returned from Firebase that looks like this:

143.418

When I run it through angulars currency filter it returns:

{{invoice.pricing.graTotal | currency}}

//Returns : $143.42

I have integrated Stripe Checkout into my application and it needs values to look like so:

14342

So Without the decimal points or dollar signs. Not formatted at all. So how would I get the original value rounded and then remove the decimal point to be sent to stripe?

I tried adding variables to the formatter:

{{invoice.pricing.graTotal | currency:undefined:0}}

But that added the dollar sign and removed the cents all together.

$143
3

There are 3 answers

0
JB Nizet On BEST ANSWER

Simply define a filter that uses

Math.round(amount * 100);
1
svatsi On

From angularJs:

{{ currency_expression | currency : symbol : fractionSize}}

So, it must be something like:

{{ invoice.pricing.graTotal | currency : "$": 2}}
0
mcadio On

I've tried many things, but this worked for me:

Math.round(parseFloat(invoice.pricing.graTotal * 100));

I assigned that to a variable and injected that into the view:

//in controller    
vm.grandtotal = Math.round(parseFloat(invoice.pricing.graTotal * 100));
//in view
{{ vm.grandtotal }}