Jump to content

array and math problems


phxcityslick

Recommended Posts

[code][9] => Array
        (
            [0] => Wins:
            [1] => 493
        )

    [10] => Array
        (
            [0] => Losses:
            [1] => 189
        )

    [11] => Array
        (
            [0] => Undecided:
            [1] => 0
        )

    [12] => Array
        (
            [0] => Credits received:
            [1] => 30,138.00
        )



<tr>
<td>Avg Credits Won per Fight:</td>
<td><?= $tw_caraway[12][1]/$tw_caraway[9][1]  ?></td>
</tr>
[/code]

by doing this the answer should be 61.131845 but it's coming out to be 0.0608519269777 this should be a whole number can soone please help me?

what is it showing it
Link to comment
https://forums.phpfreaks.com/topic/26091-array-and-math-problems/
Share on other sites

That's because you have a comma in $tw_caraway[12][1].

Try this-
[code]<tr>
<td>Avg Credits Won per Fight:</td>
<td><?php echo  (str_replace(",","",$tw_caraway[12][1])/$tw_caraway[9][1])  ?></td>
</tr>[/code]


EDIT- you should also round a bit the number, to leave only 2 digits after the decimal point-
[code]<td><?php echo  round((str_replace(",","",$tw_caraway[12][1])/$tw_caraway[9][1]),2)  ?></td>[/code]

Orio.

Archived

This topic is now archived and is closed to further replies.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.