6 Replies Latest reply on Apr 6, 2011 12:13 PM by EJP

# how to check and round down an Integer?

Newbie question:

How can I check a given Integer (not int) to see if it requires rounding, and then round down.

eg
if given Integer is 3456 - do nothing.

if given Integer is 3456.9 - round DOWN to 3456

Thanks!
• ###### 1. Re: how to check and round down an Integer?
How can I check a given Integer (not int) to see if it requires rounding, and then round down.
That's easy. Whether it is an Integer or an integer it can never need rounding, whether up, down, or sideways. It doesn't have a fractional part to round.
if given Integer is 3456.9
... the laws of Java must have been temporarily suspended. This is impossible.
1 person found this helpful
• ###### 2. Re: how to check and round down an Integer?
Oh....I see.

Let me expand then.

If I have been passed an Integer 2345 I need to return the half of its value 'rounded down'.

ie 2345 / 2 = 1172 (I need to return 1172, not 1173 or 1172.5)

Thanks.
• ###### 3. Re: how to check and round down an Integer?
That's how integers behave already. If you assign a floating-point number to an integer (int or Integer) it will truncate the fraction part.
• ###### 4. Re: how to check and round down an Integer?
Thanks for putting up with my newbiness.
• ###### 5. Re: how to check and round down an Integer?
Try this:

NumberFormat format = NumberFormat.getInstance();
format.setMaximumFractionDigits(0);
format.format(<VALUE>);
• ###### 6. Re: how to check and round down an Integer?
Why? It already is an integer, it already is rounded down.

Please read the thread before contributing.