John
John

Reputation: 111

Stripe API Charge::retrieve(['amount']) into a currency format with Twig

I am trying to format the charge amount retrieved from Stripe API. The amount from the Charge::retrieve(['amount']) is 14330000.

Within my Twig View i have the following;

{{ order.amount | number_format(0, '.', ',') }}

Which should produce;

143,000

But produces;

14,300,000

I am presuming that Stripe Charge::retrieve(['amount']) is a float

Any help to format the amount to 143,000 or even 143,000.00 would be good.

Upvotes: 1

Views: 420

Answers (1)

Alain
Alain

Reputation: 36954

order.amount may contain cents, you just need to divide it by 100.

{{ (order.amount / 100) | number_format(0, '.', ',') }}

Are you sure about the unexpected 3?

See fiddle

Upvotes: 2

Related Questions