Michael Vogt wrote:
The Struts Validator floatRange seems to have roundoff error.
For the validation.xml configuration snippet below, user input of
90.00001 fails validation, as expected, but 90.000001 does not.
<field property="baseLocalities.latitude" depends="float,floatRange">
<var>
<var-name>min</var-name>
<var-value>-90</var-value>
</var>
<var>
<var-name>max</var-name>
<var-value>90</var-value>
</var>
</field>
Is this a known problem or the expecxted behaviour?
What is the best way to work around it?
That's the expected behaviour. Floats in Java (as in most programming
languages) have limitted precision. 90.0f == 90.000001f by definition as
a result of the way floats are represented internally and how strings
are converted to float type. If float doesn't have sufficient precision
for your needs, use double instead.
If you need higher precision than even double supports, you'll need to
use java.math.BigDecimal to represent your values -- though note that
Validator may not support BigDecimal out of the box; you may need to
write custom validation rules for that (I haven't checked so YMMV).
L.
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]