Manning's Countdown to 2014
. Use discount code crdotd14 all month for 50% off every deal.
A friendly place for programming greenhorns!
Big Moose Saloon
Register / Login
Java in General
Working with Decimal values
Joined: May 01, 2009
Sep 11, 2009 09:26:20
I am working on a program that reads in decimal values.
I have the input set as Double.
for example : 23.0, 23.0, 24.0, 24.0, 25.0, 25.0, 25.234, 25.234, 25.342, 25.342, 26.0
I am trying to perform different functions depending on the value of the data.
For example if 23.0 I want to do function 1.
for value 25.234 I want to do function 2.
What is the best way to differentiate the whole number value from the value with numbers to the right of the decimal.
Joined: Oct 13, 2005
Sep 11, 2009 10:12:30
Because of the imprecision always associated with floating point arithmetic, there is probably not a "best" way, but have you tried
. . . if (number % 1 == 0.0) . . .
Joined: Apr 07, 2007
Sep 11, 2009 17:41:12
You might also want to look at
and use the scale method to check how many numbers are to the right of the decimal point.
subject: Working with Decimal values
How do you represent BIG numbers
Loss of precision worry when using Math.pow()
floating point value
short to bit ?
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter
| Powered by
Copyright © 1998-2013