adding drops the zero.

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
penguinboy
Forum Contributor
Posts: 171
Joined: Thu Nov 07, 2002 11:25 am

adding drops the zero.

Post by penguinboy »

i'm trying to add dollar values

like


$cost = "12.00";

$othercost = "12.60";

$total = $cost + $othercost;


echo "$ $total";


well i want it to echo "$ 24.60";

but instead its echoing "$ 24.6";

so how do i get around this problem, I've tried using "", '', () but noting seems to work.

thanks for any help

-pb
User avatar
volka
DevNet Evangelist
Posts: 8391
Joined: Tue May 07, 2002 9:48 am
Location: Berlin, ger

Post by volka »

you might format the output via printf/sprintf
http://www.php.net/manual/en/function.sprintf.php
Post Reply