Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Min, Max, Step - determine if a value fits in a given range

807588Jun 21 2009 — edited Jun 22 2009
This may be a bit ot, but I was looking at the JSpinnerModel and noticed that it does not implement any sort of user input validation

I need a way, given a users input, to determine if the given number falls within a given range. I have been able to validate about 90% of the time but I still have false-failures, and therefore potentially false-positives.

Example: Given a range of min=15.0, max100.0, step=0.01 how can I validate if any numeric value entered by a user matches that range.

I think i've got the min and max test down :)

I'll give an example of what I have tried:
float t1 = (value-cMinValue)/cStepValue;
// less than min
boolean minTest = value >= cMinValue;
// more than max
boolean maxTest = value <= cMaxValue;
// t1 should be a non-negative value
boolean negTest = (t1 == Math.abs(t1));
// t1 should be a non-decimal value
boolean wholeTest = (t1 == (int)t1);
boolean ok = minTest && maxTest && wholeTest && negTest;
I have tried several searches, but maybe I just don't know the proper terminology for what I am trying to do -- any input, pointers or algorithm details would be a great help

tia
kw
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jul 20 2009
Added on Jun 21 2009
11 comments
974 views