Java:舍入到最接近的5的倍数(向上或向下) [英] Java: round to nearest multiple of 5 (either up or down)

查看:157
本文介绍了Java:舍入到最接近的5的倍数(向上或向下)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我需要将数字四舍五入到最接近的5(向上或向下)。例如,以下是数字列表及其旁边需要向上/向下舍入的数字。

I need to round a number to nearest multiple of 5 (either up or down). For example, here are the list of numbers and the number next to it that it needs to round up/down to.

12.5  10
62.1  60
68.3  70
74.5  75
80.7  80

数字只会是正数。

推荐答案

尚未测试,但 5 * (Math.round(f / 5)); 应该可以工作

haven't tested it, but 5*(Math.round(f/5)); should work

这篇关于Java:舍入到最接近的5的倍数(向上或向下)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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