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! Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
jxrd Posted May 26, 2009 Share Posted May 26, 2009 round() or number_format(). Quote Link to comment 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? Quote Link to comment 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"; Quote Link to comment 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"; Quote Link to comment 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. Quote Link to comment 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. Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.