Jump to content


Photo

Decimal Help


  • Please log in to reply
4 replies to this topic

#1 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 03 September 2006 - 02:42 PM

Hello,

I have a quick question. I am doing a stats program for a hockey team and the question I have is that I have the decimals correct for the goaltenders goals against average and save % as I wish, except for the fact that if its an even # like 2 it will display 2 rather than 2.00. Works fine when the #'s are not even rounding off to 2 and 3 decimals respectively.

Here is the code for the GAA....

$p_array[$playerid][gaa] = ROUND('1.00' * ($p_array[$playerid][goalsa]) * (60/$p_array[$playerid][minutes]), 2);

Any help would be appreciated......thanks in advance !

#2 AndyB

AndyB
  • Staff Alumni
  • Advanced Member
  • 5,465 posts
  • LocationToronto

Posted 03 September 2006 - 03:03 PM

http://ca.php.net/ma...mber-format.php
Legend has it that reading the manual never killed anyone.
My site

#3 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 03 September 2006 - 03:35 PM

thanks, thought there may have been something I could do here in this snippet....

$p_array[$playerid][gaa] = ROUND('1.00' * ($p_array[$playerid][goalsa]) * (60/$p_array[$playerid][minutes]), 2);

like this....

$p_array[$playerid][gaa] = ROUND('1.00' * ($p_array[$playerid][goalsa]) * (60/$p_array[$playerid][minutes]), 2,'.',' ');



#4 wildteen88

wildteen88
  • Staff Alumni
  • Advanced Member
  • 10,482 posts
  • LocationUK, Bournemouth

Posted 03 September 2006 - 04:04 PM

wrap number_format around your round function:
$pcent = round('1.00' * ($p_array[$playerid]['goalsa']) * (60/$p_array[$playerid]['minutes']), 2);

$p_array[$playerid]['gaa'] = number_format($pcent, 2, '.', ',');


#5 phpbeginner

phpbeginner
  • Members
  • PipPipPip
  • Advanced Member
  • 215 posts

Posted 03 September 2006 - 04:18 PM

Thanks so much.....works beautiful.




0 user(s) are reading this topic

0 members, 0 guests, 0 anonymous users