Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Showing two decimal places on a number with 0 or 1 decimals

Status
Not open for further replies.

adam0101

Programmer
Jun 25, 2002
1,952
US
How can I get the following numbers:
2
2.3
2.45
2.456

To appear as:
2.00
2.30
2.45
2.46

If I try to use "round(num,2)", the output is incorrect:
2
2.3
2.45
2.46

Thanks
 
printf or sprintf should work.
Code:
printf("%.2f", $val);
$string = sprintf("%.2f", $val);
//Daniel
 
Thank you,
After posting this, I searched the forum and found out about the number_format() function as well. Next time I'll search the forum first.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top