I'm using mysql and php to download a data type that should be in currency format. I have chosen a datatype of float to show the numbers past the decimal place but they go on too long. I only want it to go to 2 decimal places...
Can any one help?
number_format() will round the number to the specified decimal place. It will return a string, suitable to, as op says, "show the numbers": number_format(4.00987) will echo as "4.01". round() won't show trailing decimal zeroes: round(4.000123) will echo as "4". If calculations are to be done, they will pesumably be done with the unaltered float.
Agreed, definitely use number_format. You don't want $4.50 to show up as '$4.5'. Just be sure to only do this when it is displayed, as rounding before will affect calculations, and the return is a string rather than a float.
Database design and performance optimization, custom PHP scripts, and publicly available resources for developers! http://www.zeropride.com