Forum Moderators: coopster

Message Too Old, No Replies

Hey, what happened to the ".00"'s?

After a adding 2 variables

         

neophyte

8:47 am on Mar 14, 2006 (gmt 0)

10+ Year Member



Hello All -

On a particular php page, I'm drawing 2 different numbers from 2 fields in a table. These two fields both have a type of float(3,2).

Then, I echo an addition of both numbers to my page, like this: echo ("$standard" + "$roomHigh");

$standard has the number "57.00". $roomHigh has the number "19.00".

Strictly speaking, all is well, as what echos to the page is the sum of both numbers: "76". But that's the problem...as my client pointed out. He wants to reflect "76.00", not just "76", because other numbers on the page (which are echoed without any calculation) show up with their trailing zero's intact.

So... there must be an easy fix to this (one would hope). I thought of tacking on the trailing zeros manually, but that doesn't seem like a good solution if there's a built-in way to do it.

All assistance greatly appreciated.

Neophyte.

tomda

9:00 am on Mar 14, 2006 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



Yeah, there is!
Look for number_format().

$nb1 = 19.00;
$nb2 = 57.00;
$nb =$nb1 + $nb2;
echo number_format($nb, 2);

neophyte

10:47 am on Mar 14, 2006 (gmt 0)

10+ Year Member



Cool man! Worked like a charm...thanks a lot!

Absolutly slicker than a soup sandwich!

Neophyte