fjbatresv
fjbatresv

Reputation: 137

Show the final ".00" on exact numbers php

00" on the exact numbers, but only showing the thousand separator too. Here is a example:

number_format(1256, 2, '.', ',');

that show me : 1,256 and I need that this show: 1,256.00

I tried with money format, this is that happened:

money_format('%i', 1256);

the result of this is: 1256.00 like you can see this method don't return the thousand separator...

Thanks for the help.

$form['field name']->setData(number_format(1256, 2, '.', ','));

Upvotes: 1

Views: 107

Answers (3)

fjbatresv
fjbatresv

Reputation: 137

Sorry to all... that was only a trouble with the "()" order...

that was:

$form['filed name']->setData(numberformat(1256), 2, '.', ',');

And that is the reason because the number format doesn't work completely...

Upvotes: 0

mamdouh alramadan
mamdouh alramadan

Reputation: 8528

you can set the locale as follows:

$number = 12354.65;
setlocale(LC_MONETARY, 'en_US');
echo money_format('%i', $number);

FIDDLE

Upvotes: 1

Pavel Štěrba
Pavel Štěrba

Reputation: 2912

Just put it together:

number_format(money_format('%i', 1256), 2, '.', ',');

See this demo.

Upvotes: 1

Related Questions