Page 1 of 1

Round a Full Number to Decimal

Posted: Sat Apr 29, 2006 10:36 pm
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'

Posted: Sat Apr 29, 2006 10:58 pm
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 :)

Posted: Sat Apr 29, 2006 11:14 pm
by Christopher
I'd go with the number_format() function.

Posted: Sat Apr 29, 2006 11:32 pm
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...