Reputation: 376
I have the below simple number, $total = 1060;
, that i need to format as below using PHP
10.60
What i tried
$total = 1060;
number_format($total, 2)
But the result showing is 1,060.00
instead of the below 10.60
Plus I need it to be a dot .
and not a comma ,
as the separator
Upvotes: 1
Views: 56
Reputation: 26450
All you need to do is divide by 100 in before you format it. That makes it 10.6
(because the second decimal is zero, it's not needed and stripped away), and then you format it to have two decimal places.
$total = 1060;
number_format($total/100, 2); // 10.60
Upvotes: 5