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
  • 56,466
  • 29
  • 168
  • 265
agarwal_achhnera
  • 2,582
  • 9
  • 55
  • 84

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
  • 77,191
  • 7
  • 105
  • 161
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,821
  • 4
  • 17
  • 35