Re: round number to nearest integer.
From: Sudsy (bitbucket44_at_hotmail.com)
Date: 06/05/04
- Next message: Gary Labowitz: "Re: Curious"
- Previous message: Fred: "round number to nearest integer."
- In reply to: Fred: "round number to nearest integer."
- Next in thread: Fred: "Re: round number to nearest integer."
- Reply: Fred: "Re: round number to nearest integer."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Date: Sat, 05 Jun 2004 00:14:23 -0400
Fred wrote:
> I received some help here a week ago about rounding up numbers using
> Math.ceil. Unfortunately it turns out that I need to round up/down numbers
> to their nearest integer.
>
> Example 107200.01 needs to be rounded down to 107200.
> 107200.99 neads to be rounded up to 107201.
>
> Is there any way to accomplish this?
>
>
> Original code:
>
> MPoriginalFormat2= (int) Math.ceil(MPoriginalFormat);
From the javadocs for java.lang.StrictMath:
round
public static long round(double a)
Returns the closest long to the argument. The result is rounded to
an integer by adding 1/2, taking the floor of the result, and casting
the result to type long. In other words, the result is equal to the
value of the expression:
(long)Math.floor(a + 0.5d)
Give you any ideas?
ps. There's also a method by the same name which takes a float argument
and returns an int.
- Next message: Gary Labowitz: "Re: Curious"
- Previous message: Fred: "round number to nearest integer."
- In reply to: Fred: "round number to nearest integer."
- Next in thread: Fred: "Re: round number to nearest integer."
- Reply: Fred: "Re: round number to nearest integer."
- Messages sorted by: [ date ] [ thread ] [ subject ] [ author ]
Relevant Pages
|