Re: rounding to .5
Re: rounding to .5
- Subject: Re: rounding to .5
- From: Christian Brunschen <email@hidden>
- Date: Tue, 5 Jul 2005 14:02:10 +0200 (CEST)
On Tue, 5 Jul 2005, Dev WO wrote:
Hi,
I've been searching for a simple way to handle ratings in a WO app:
users can only affect integer (1 to 5), and I'd like to provide the overall
rating with .5 precision (1, 1.5, 2, ...).
I know I can make a method with if 1.25 < overallRating < 1.76 then
overallRating = 1.5, etc but I was wondering if there's any built-in java
method for rounding to .5.
I red the Math API and looked at the rounding modes, but it doesn't look like
what I need...
Is there something more "direct" to do the .5 rounding than the if... method?
How about
double rounded = Math.round(2.0 * original) / 2.0;
?
This will round '2.0 * original' to the nearest integer, and by dividing
that by 2,.0 you get your original value, rounded to the learest half 0.5
Thanks:)
Best wishes,
Xavier
// Christian
_______________________________________________
Do not post admin requests to the list. They will be ignored.
Webobjects-dev mailing list (email@hidden)
Help/Unsubscribe/Update your Subscription:
This email sent to email@hidden