• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

how to check if a double is exact multiple of an increment value

 
premkumar bhaskal
Greenhorn
Posts: 2
Eclipse IDE Firefox Browser
  • Likes 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi,
I want to check if a given double number is multiple of any given increment value.
Eg. i want to check if number 2.3 is a multiple of 0.01.
For this i wrote the following code.
.
but i am getting the below result:
the result is 229.99999999999997
the number 2.3 is not exactly divisble

Can someone suggest a better and robust way to check the multiplicity of double values, which will work for any double values.

Thanks & Regards
 
Rob Spoor
Sheriff
Pie
Posts: 20494
54
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use BigDecimal, or use int / long to represent the double times X (with X being some power of 10). float and double simply are never accurate enough; see item #20 of our beginners FAQ for more info.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic