limiting a number to 2 decimal places

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
psychotomus
Forum Contributor
Posts: 487
Joined: Fri Jul 11, 2003 1:59 am

limiting a number to 2 decimal places

Post by psychotomus »

how can I limited a number to 2 decimal places like

2.34

or have 2.346 be 2.35
User avatar
John Cartwright
Site Admin
Posts: 11470
Joined: Tue Dec 23, 2003 2:10 am
Location: Toronto
Contact:

Post by John Cartwright »

User avatar
s.dot
Tranquility In Moderation
Posts: 5001
Joined: Sun Feb 06, 2005 7:18 pm
Location: Indiana

Post by s.dot »

take a look at the round() function

Code: Select all

$number = 5.73458565;
$twodecimals = round($number,2);
for more functions dealing with this see ceil() floor() number_format()
Post Reply