Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

i am making a cricket stats page and in 1 over there are 6 balls, however if i put in 0.7 id dose not make it 1.1, how can i use php to make it do this?
This is all the code i have got (im using mysql):

<?php echo $row['o'] ?>
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
162 views
Welcome To Ask or Share your Answers For Others

1 Answer

$x = 0.7;

$overs = floor(($x * 10) / 6);
$balls = ($x * 10) - ($overs * 6);

echo $overs.'.'.$balls;

But you might want to use an integer input (the number of balls bowled) rather than a decimal value.

$x = 7;

$overs = floor($x / 6);
$balls = $x - ($overs * 6);

echo $overs.'.'.$balls;

This logic can be simplified using the % modulus operator, but I've shown it longhand to try and help you understand the principle


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...