Php:当数字达到0.6时将其设为1 [英] Php: when a number gets to 0.6 make it 1

查看:122
本文介绍了Php:当数字达到0.6时将其设为1的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在制作板球统计信息页面,并且在1处有6个球,但是如果我输入0.7 id不能使其达到1.1,我如何使用php来做到这一点? 这就是我所拥有的所有代码(使用mysql):

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'] ?>

推荐答案

$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

这篇关于Php:当数字达到0.6时将其设为1的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆