Hi,
I'm using hibernate validator for validate field with double precision and I tried to validate this value "0.001".
Example:
Code:
...
@Digits(integer=12,fraction=3)
private Double value = 0.001d;
..
I did some tests with the Double class and saw what toString method append one zero at final of number.
The code below explain it.
Code:
for (int i = 1; i <= 999; ++i) {
String s = Double.valueOf (i / 1000.0).toString();
if (s.length() > 5) {
System.out.println (s);
}
}
result :
/*
0.0010
0.0010
0.0020
0.0030
0.0040
0.0050
0.0060
0.0070
0.0080
0.0090
*/
Mathematically, "0.001" is equal "0.0010", but the validator return false because "0.0010" has 4 fractional digits.
How can I solve this?
Thanks in advance!