Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

@DecimalMin / @DecimalMax generating invalid value (missing fractional part) #288

Closed
Redid opened this issue Dec 4, 2017 · 2 comments
Closed
Labels
Milestone

Comments

@Redid
Copy link

Redid commented Dec 4, 2017

Hi random-beans Team,

There is a problem with handling @DecimalMin / @DecimalMax as it is not generating fractional part of decimal. I think it is connected with not supporting @Digits, but you should know about it anyway :)

Example:

public class TestDecimal {
    @DecimalMax("1.00")
    @DecimalMin("0.01")
    private BigDecimal bigDecimal;

    public BigDecimal getBigDecimal() {
        return bigDecimal;
    }

    public void setBigDecimal(BigDecimal bigDecimal) {
        this.bigDecimal = bigDecimal;
    }
}

It is always returning "0", which is invalid value for this case.

Best regards,
Redid

fmbenhassine added a commit that referenced this issue Dec 6, 2017
@fmbenhassine
Copy link
Member

Hi @Redid

Thank you for pointing out this issue!
Indeed, RB is failing on this case.

Let me plan the fix for next release.

Kr
Mahmoud

@fmbenhassine fmbenhassine added this to the v3.8.0 milestone Dec 6, 2017
fmbenhassine added a commit that referenced this issue Nov 18, 2018
fmbenhassine added a commit that referenced this issue Nov 18, 2018
Random BigDecimal generation  was based on long instead of double.
When specifying a min as 0.01, a min of 0 was used.
This commit fixes the issue by using the double type to avoid any data
precision loss.
@fmbenhassine
Copy link
Member

Hi,

This issue was deeper than I thought. Random BigDecimal generation was based on a delegate LongRandomizer which yields in data precision loss (a min of 0.01 was incorrectly converted to 0). This has been fixed and deployed to maven central in version 3.8.0-SNAPSHOT.

@Redid Can you give the fix a try with version 3.8.0-SNAPSHOT (Here is how to import it just in case). Many thanks upfront!

Kr,
Mahmoud

NB: As a side note, while working on this issue, I reported a similar problem with floats (see #318) which I fixed BTW.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Projects
None yet
Development

No branches or pull requests

2 participants