如何获得最接近的十分之一 [英] how to get nearest tenth of a double

查看:91
本文介绍了如何获得最接近的十分之一的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我想在java中将两个数字四舍五入,使其转换为最接近的第十个,如下所示。

I want to round up double number in java such that it converts to it's nearest tenth like below..


0.1--->0.1
0.3--->1
1----->1
1.5---->10
92---->100
4.0E8-->1.0E9
etc

我怎么能这样做
其实我的目的是设置Y -axis在图表上,如果最大值为0.1,那么num_ spacing将设置为.01,如果是.3然后转换为1然后将num_ spacing设置为.1等等

How can I do it Actually my intention is to set Y-axis on chart, if max value is 0.1 then num_ spacing will set to .01 if it is .3 then convert to 1 then set num_ spacing to .1 and so on

推荐答案

尝试将其翻译成您的语言,我已经在Matlab中编写了它,但它应该是显而易见的

Try translating this into your language, I've written it in Matlab but it ought to be obvious

10^ceil(log10(x))

当然,这只会如果 x 为正值,则可以正常工作。

Of course, this will only work if x is positive.

这篇关于如何获得最接近的十分之一的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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