Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I add a decimal to my number?

I'm doing some calculations and I end up with 65.0 or 43.5.
I need to add a zero to this number so that my number comparison works:

$this->sub_total == $order_sub_total

I've tested using number_format():

$total = number_format($total, 2, '.');

But that gives me er msg: Wrong parameter count for number_format()

I'm tempted to just do:

$total = $total.'0';

But I think that is a bad idea in case the number is 35.43.

So how can I add a extra decimal to my number?

like image 723
Steven Avatar asked Aug 06 '12 13:08

Steven


1 Answers

With number_format() you need either two or four parameters. Three will always through an error.

For you both of the following will work identically:

$total = number_format($total, 2);

$total = number_format($total, 2, '.', ',');
like image 56
John Conde Avatar answered Oct 04 '22 22:10

John Conde