John John - 8 days ago 8
PHP Question

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,330,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.

Answer

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

Comments