我正在寻找一种方法来四舍五入到最接近的 500.我一直在使用:
math.ceil(round(8334.00256 + 250, -3))由此,我在 ArcGIS 中制作的地图的比例尺中获得了一个值.我有能力读取和写入比例因子(即 1:8334 ....基本上,你设置千分之一,它默认为一个比率)如果比例因子不是 500 的因子,我想四舍五入到下一个 500.math.ceil 将四舍五入任何十进制值,而 round(n,-3) 将四舍五入到最接近的千位,但我正在努力寻找一种方法来四舍五入到最接近的 500.
有什么建议吗?谢谢,迈克
解决方案缩放、圆形、非缩放:
round(x/500.0) * 500.0编辑:要向上取整到 500 的下一个倍数,请使用与 math.ceil() 相同的逻辑,而不是 round():
math.ceil(x/500.0) * 500.0I'm looking to find a way to round up to the nearest 500.I've been using:
math.ceil(round(8334.00256 + 250, -3))Whereby I have a value from a scale in a map I am making in ArcGIS. I have the ability to read and write the scale factor (i.e. 1:8334....basically, you set the thousandth and it defaults to a ratio) If the scale factor isn't a factor of 500, I want to round up to the next 500. The math.ceil will round up any decimal value, and the round(n,-3) will round to the nearest thousandth, but I'm struggling to find a way to round to the nearest 500.
Any suggestions? Thanks, Mike
解决方案Scale, round, unscale:
round(x / 500.0) * 500.0Edit: To round up to the next multiple of 500, use the same logic with math.ceil() instead of round():
math.ceil(x / 500.0) * 500.0
更多推荐
四舍五入到最接近的 500,Python
发布评论