Hi all,

Yeah, that was easy to spot: BigDecimal is only accurate when provided with
a string or fixed input (e.g. integer or long).
Doubles and floats are inherently inaccurate (as they are non-exact values).

So if you change your code to ...

testField.setMinimum(new BigDecimal(“0.01"));

… it will work correctly.

Met vriendelijke groet,
Kind regards,

Bas Gooren

Op 20 december 2023 bij 15:25:23, Sven Meier (s...@meiers.net) schreef:

Hi Eric,

you can read in the javadoc, why your first solution is 'unpredictable':

https://docs.oracle.com/en/java/javase/17/docs/api/java.base/java/math/BigDecimal.html#%3Cinit%3E(double)

Sven

On 20.12.23 15:18, Eric Hamel wrote:
> Hi Bas,
>
> Thanks for the response.
>
> I discovered the NumberTextField had its own RangeValidator 2 seconds
after posting. With that said, I’m getting the same issue when using it.
>
> To be clear, I’m not getting any Exceptions, everything seems to work
fine, but the form validation fails if the user types in 0.01.
>
>
> Form<BaseDTO> form = new Form<>(“form”, getModel());
> add(form);
>
> NumberTextField<BigDecimal> testField = new
NumberTextField<BigDecimal>(“testField”, new
PropertyModel<BigDecimal>(form.getModel(), “testProp”));
> form.add(testField);
>
>
> I’ve been digging and I found the oddity:
>
> If I set the min value as follows:
>
> testField.setMinimum(new BigDecimal(0.00));
>
> When the user enters 0.01, the following feedback message is showed:
>
> The value of ’testField’ must be between 0.01 and 999,999.99.
>
> However, if I set the min value with:
>
> testField.setMinimum(BigDecimal.valueOf(0.00));
>
> The user can enter 0.01 and NO feedback message is showed.
>
>
>
> -------------
> Eric H.
>
>
>
>
>
>> On Dec 20, 2023, at 8:48 AM, Bas Gooren <b...@iswd.nl> wrote:
>>
>> Hi Eric,
>>
>> First off: according to the source of NumberTextField, it automatically
adds a RangeValidator (see NumberTextField#onConfigure). So you shouldn’t
need to add the RangeValidator yourself.
>>
>> Regarding your problem: what kind of error messages are you getting?
>>
>> The range validator (or more specifically: the AbstractRangeValidator
class) handles the comparison between min, max and actual values using
compareTo. So there should not be any issues with rounding.
>>
>> Please share the code you use to initialize the relevant field, perhaps
we can spot a mistake.
>>
>> Met vriendelijke groet,
>> Kind regards,
>>
>> Bas Gooren
>>
>> Op 20 december 2023 bij 14:38:53, Eric Hamel (eric.ha...@albanyitg.com
<mailto:eric.ha...@albanyitg.com>) schreef:
>>
>>> Good morning,
>>>
>>> We encountered an issue this morning with our use of
RangeValidator<BigDecimal>.
>>>
>>> The customer requested a validation for amounts between 0.01 and
999,999.00.
>>>
>>> We have a NumberTextField<BigDecimal> to which we added the
RangeValidator. If the user enters 0.01 the validation fails.
>>>
>>> If I set the min value to 0.009 I can get it to work but the error
messages are off.
>>>
>>> I’m wondering if it’s a rounding or scale issue but I cannot figure out
how to make the RangeValidator work.
>>>
>>> Anyone have any insight on this ?
>>>
>>> Thank you.
>>> Eric H.
>>>
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org <mailto:
users-unsubscr...@wicket.apache.org>
>>> For additional commands, e-mail: users-h...@wicket.apache.org <mailto:
users-h...@wicket.apache.org>

---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@wicket.apache.org
For additional commands, e-mail: users-h...@wicket.apache.org

Reply via email to