I got an issue.
Say I wanna do 20/60 in php and the result is 0.33 Well I want it to show the 3rd number after decimal so 0.333
I cant see to get to this work any ideas ?
I got an issue.
Say I wanna do 20/60 in php and the result is 0.33 Well I want it to show the 3rd number after decimal so 0.333
I cant see to get to this work any ideas ?
What have you tried? It should just be a matter of say, setting the precision in [man]round/man.
I tried round and used round($row_name['ratio'],3); It dont work
Let's try a simple test script:
<?php
$num = 20 / 60;
echo round($num, 3);
?>
$num = 20 / 60;
echo number_format($num, 3);
number_format might be overkill here, and possibly even wrong. Consider:
$num = 200000 / 60;
echo number_format($num, 3);
Nothing wrong with round(), but I'm a [sp]rintf() kind of guy.
printf("%.3f", 20 / 60);
I got it guys thanks for all help. You code PHP for so long then take a break and you forget everything lol.
I just ended up doing round($row_name['loot]/$row_name['points'],3);
Wouldn't round in some scenarios not return three sig figs? with the 60 / 20 you still get the three, but if these numbers change and have fractions you may end up with it being rounded to a whole number, number_format will always retain the decimals. By wrong did you mean the comma potentially causing problems? It can be removed.
number_format($num, '.', '');
Sorry to sound argumentative, I'm trying to fish some knowledge out of you laserlight to better my understanding.
Wouldn't round in some scenarios not return three sig figs?
That's right. In such a case, number_format() or printf() would be required.
By wrong did you mean the comma potentially causing problems? It can be removed.
Of course, but not in your example usage.
Thank you for taking the time to break it down for me, you guys really help put things in perspective.