Round a Full Number to Decimal

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
nzhuda
Forum Newbie
Posts: 1
Joined: Sat Apr 29, 2006 10:35 pm

Round a Full Number to Decimal

Post by nzhuda »

Hello All
I am new in PHP. I can not round a full number to decimal. Like I want to round 123 to 123.00. How can I do this.


Thanks.

Nazmul
[url=http://forums.devnetwork.net/viewtopic.php?t=30037]Forum Rules[/url] Section 1.1 wrote:2. Use descriptive subjects when you start a new thread. Vague titles such as "Help!", "Why?" are misleading and keep you from receiving an answer to your question.
HawleyJR | Title changed from :( to 'Round a Full Number to Decimal'
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

Code: Select all

$val = 12;
printf('Output: %2.2f',  $val);
Check out: http://ca3.php.net/manual/en/function.sprintf.php

Cheers :)
User avatar
Christopher
Site Administrator
Posts: 13596
Joined: Wed Aug 25, 2004 7:54 pm
Location: New York, NY, US

Post by Christopher »

I'd go with the number_format() function.
(#10850)
alex.barylski
DevNet Evangelist
Posts: 6267
Joined: Tue Dec 21, 2004 5:00 pm
Location: Winnipeg

Post by alex.barylski »

arborint wrote:I'd go with the number_format() function.
http://ca.php.net/manual/en/function.sprintf.php

Does the same thing, only more flexible albeit more cryptic to use...
Post Reply