-->
These old forums are deprecated now and set to read-only. We are waiting for you on our new forums!
More modern, Discourse-based and with GitHub/Google/Twitter authentication built-in.

All times are UTC - 5 hours [ DST ]



Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 
Author Message
 Post subject: Problem with @Digits
PostPosted: Mon Jul 27, 2009 3:10 pm 
Newbie

Joined: Mon Jul 27, 2009 2:23 pm
Posts: 1
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!


Top
 Profile  
 
 Post subject: Re: Problem with @Digits
PostPosted: Tue Jul 28, 2009 6:12 am 
Hibernate Team
Hibernate Team

Joined: Thu Apr 05, 2007 5:52 am
Posts: 1689
Location: Sweden
Hmm, I guess the solution is to remove trailing '0's. In fact the dgit validator implementation of the legacy hibernate validator did exactly that.

I created an Jira issue HV-192 and applied the fixes on the trunk of Hibernate Validator. It will go into the next release.

If you need a solution right now, you can either use a snapshot of Hibernate Validator or you could use a custom constraint for now.

--Hardy


Top
 Profile  
 
Display posts from previous:  Sort by  
Forum locked This topic is locked, you cannot edit posts or make further replies.  [ 2 posts ] 

All times are UTC - 5 hours [ DST ]


You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum

Search for:
© Copyright 2014, Red Hat Inc. All rights reserved. JBoss and Hibernate are registered trademarks and servicemarks of Red Hat, Inc.