3

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

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

Ali
  • 54,239
  • 29
  • 159
  • 255
agarwal_achhnera
  • 2,516
  • 8
  • 53
  • 77

2 Answers2

10

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

10^ceil(log10(x))

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

High Performance Mark
  • 75,673
  • 7
  • 99
  • 152
0

you can have a look..

              double a = 120.1;
    double last_digit_rem = 10 - (a % 10);
    System.out.println(a+last_digit_rem);

It will work for negative numbers also...

Srinivas B
  • 1,761
  • 3
  • 14
  • 34