Padgoi Posted May 26, 2009 Share Posted May 26, 2009 Hi, I have this function but it's displaying a VERY long number. I want to limit the number to 2 decimal places. How would I go about doing this? Any help is appreciated. $total = $field / $get_topics[0]; $this->output .= "\t<td><font face=arial size=1/>$total</font></td>\n"; Thanks! Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/ Share on other sites More sharing options...
Maq Posted May 26, 2009 Share Posted May 26, 2009 number_format EDIT: Better yet, you can use money_format. Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842392 Share on other sites More sharing options...
jxrd Posted May 26, 2009 Share Posted May 26, 2009 round() or number_format(). Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842393 Share on other sites More sharing options...
Padgoi Posted May 26, 2009 Author Share Posted May 26, 2009 Sorry guys, my PHP is kinda weak. I'm trying this but it's not working. $total = $field / $get_topics[0]; round($total, 2); $this->output .= "\t<td><font face=arial size=1/>$total</font></td>\n"; Where exactly do I put the round() function? Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842410 Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 What do you mean PHP is weak? You just called a function without storing the value. $total = round($field / $get_topics[0]); $this->output .= "\t<td><font face=arial size=1/>$total</font></td>\n"; Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842413 Share on other sites More sharing options...
gevans Posted May 26, 2009 Share Posted May 26, 2009 @Ken He said my PHP is kinda weak @Padgoi <?php $total = $field / $get_topics[0]; $total = round($total, 2); $this->output .= "\t<td><font face=arial size=1/>$total</font></td>\n"; Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842417 Share on other sites More sharing options...
Ken2k7 Posted May 26, 2009 Share Posted May 26, 2009 Oops, typo there. My point was it's not a PHP issue, but logic or programming in general. If you call a function that returns a value, but you don't store it in a variable, nothing happens. Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842430 Share on other sites More sharing options...
Padgoi Posted May 26, 2009 Author Share Posted May 26, 2009 Thanks fellas, got it working. Much obliged. Link to comment https://forums.phpfreaks.com/topic/159711-solved-php-division-rounding-to-2-decimal-places/#findComment-842439 Share on other sites More sharing options...
Recommended Posts
Archived
This topic is now archived and is closed to further replies.