andy armstrong

Ranch Hand

Posts: 154

posted 14 years ago

You don't need an open source utilty, you simply need to use the % (modulus) operator, which returns the remainder when the first number is divided by the second:

Therefore, 1.30 % .25 returns 0.050000000000000044 (doubles are unfortunatley prone to rounding errors); that does not equal 0.0, so the functions returns false

1.75 % .25 does equal 0.0, so the function returns true.

To get around the rounding errors problem, you might want to set up a tolerance threshold; that is if (mathemetically speaking, not Java speaking) -0.000000001 < result < 0.00000001 is true then return true....

Therefore, 1.30 % .25 returns 0.050000000000000044 (doubles are unfortunatley prone to rounding errors); that does not equal 0.0, so the functions returns false

1.75 % .25 does equal 0.0, so the function returns true.

To get around the rounding errors problem, you might want to set up a tolerance threshold; that is if (mathemetically speaking, not Java speaking) -0.000000001 < result < 0.00000001 is true then return true....

Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.

Cindy Glass

"The Hood"

Sheriff

Sheriff

Posts: 8521

Cindy Glass

"The Hood"

Sheriff

Sheriff

Posts: 8521