如何将数字四舍五入到最接近的10? [英] How to round up a number to nearest 10?

查看:99
本文介绍了如何将数字四舍五入到最接近的10?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何在php中将数字四舍五入到最接近的10?

How can we round off a number to the nearest 10 in php?

说我有23,我将使用什么代码将其四舍五入为30?

Say I have 23, what code would I use to round it off to 30?

推荐答案

floor()将关闭.

ceil()将上升.

round()默认情况下会最接近.

round() will go to nearest by default.

除以10,计算出ceil,然后乘以10以减少有效数字.

Divide by 10, do the ceil, then multiply by 10 to reduce the significant digits.

$number = ceil($input / 10) * 10;

我已经用这种方式做了很久了..但是TallGreenTree的答案更干净.

I've been doing it this way for so long.. but TallGreenTree's answer is cleaner.

这篇关于如何将数字四舍五入到最接近的10?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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