maharamDan
IS-IT--Management
Hello. I am trying to figure out batting average. All works well for lets says 4/6. I get a .666 average.
But when is it something like 5/10 which is .5 That is when things go wrong.
How would I go about getting it displayed with zero's before the decimal? for example .500 batting average.
thanks in advance.
<code>
<?php
$hits = 5;
$at_bat = 10;
$div_value = $hits / $at_bat;
$average = substr("$div_value", 1, 4);
echo "$average";
?> </code>
But when is it something like 5/10 which is .5 That is when things go wrong.
How would I go about getting it displayed with zero's before the decimal? for example .500 batting average.
thanks in advance.
<code>
<?php
$hits = 5;
$at_bat = 10;
$div_value = $hits / $at_bat;
$average = substr("$div_value", 1, 4);
echo "$average";
?> </code>