-7

I have a double value = 1.6 i want to round it up like 2.in java can some one Help me.

  • 2
    Please do some research before asking a question in the future. A simple google search for "rounding in java" would have been more than sufficient. – Mage Xy Feb 29 '16 at 18:17

4 Answers4

4

Try to use Math.round:

  int valueRound = (int) Math.round(value);
Abdelhak
  • 8,299
  • 4
  • 22
  • 36
1

If you always want the ceil value, you could use Math.ceil:

int value = (int) Math.ceil(1.6);
Atri
  • 5,511
  • 5
  • 30
  • 40
1

Alternatively, if you want to round to the lowest decimal;

Math.floor(1.6)
comjens
  • 23
  • 6
0

The general way for rounding in Java is this one. You can configure the scale to which you round as well as when you want to round up and when you want to round down:

new BigDecimal(value).setScale(1.0, RoundingMode.HALF_UP).doubleValue();
Matthias Wimmer
  • 3,789
  • 2
  • 22
  • 41