aspose file tools
The moose likes Java in General and the fly likes Working with Decimal values Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » Java in General
Reply Bookmark "Working with Decimal values" Watch "Working with Decimal values" New topic
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
    
    4
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]
 
I agree. Here's the link: http://ej-technologies/jprofiler - if it wasn't for jprofiler, we would need to run our stuff on 16 servers instead of 3.
 
subject: Working with Decimal values
 
Similar Threads
Loss of precision worry when using Math.pow()
How do you represent BIG numbers
Numeric Format
short to bit ?
floating point value