| Author |
Working with Decimal values
|
Rudy Rodriguez
Greenhorn
Joined: May 01, 2009
Posts: 29
|
|
Hi
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.
Thanks
Rudy
|
 |
Campbell Ritchie
Sheriff
Joined: Oct 13, 2005
Posts: 32712
|
|
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) . . .
?
|
 |
Jeff Storey
Ranch Hand
Joined: Apr 07, 2007
Posts: 230
|
|
|
You might also want to look at BigDecimal and use the scale method to check how many numbers are to the right of the decimal point.
|
Jeff Storey
Software Developer
[url]http://jeffastorey.blogspot.com[/url]
|
 |
 |
|
|
subject: Working with Decimal values
|
|
|