This week's book giveaway is in the Design forum.
We're giving away four copies of Design for the Mind and have Victor S. Yocco on-line!
See this thread for details.
Win a copy of Design for the Mind this week in the Design forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

validations problems(decimal value check?)

 
SRI KUMAR
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem: Validation not working
part of code related to this:
------------------------------
String score = request.getParameter("testScore");
double highValue = 21.0; //max value possible
.
.
.
Case 1:
double testScore = Double.parseDouble(score );
if(testScore > lowValue )
{
err message.......
}
Case 2:
int testScore = Integer.parseInt(score);
if(testScore > 21 )
{
err message.......
}
But in both the cases I could not get the error message I wanted, when I entered 21.34 or some decimal value. It gave an error message for 22 though.
In short:
how do I check for any value greater than 21.00(decimal value)
[ July 15, 2003: Message edited by: SRI KUMAR ]
 
Maulin Vasavada
Ranch Hand
Posts: 1873
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hi SRI
it would be more helpful if u can be more detailed about the code you have.
please specify what is "lowValue" in ur code.
also, i see that u don't have "break;" statement in any case...if its not there then put it otherwise switch() will behave unexpectedly...
regards
maulin
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
In case 2, instead of Integer.parseInt(...) try Double.parseDouble(...) (just as in case 1). If you to Integer.parseInt("21.34"), the parsing routing truncates the resulting integer to 21.
 
SRI KUMAR
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Problem: Validation still not working
part of code related to this:
------------------------------
String score = request.getParameter("testScore");
double highValue = 21.0; //max value possible
.
.
.
Case 1:
double testScore = Double.parseDouble(score );
if(testScore > highValue )
{
err message.......
break;
}

I could not get the error message I wanted, when I entered 21.34 or some decimal value. It gave an error message for 22 though. I observed it is not entering the if condition when I enterd 21.09 or some decimal value..
In short:
how do I check for any value greater than 21.00(decimal value)
 
Joel McNary
Bartender
Posts: 1840
Eclipse IDE Java Ruby
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
what you might try to do for debugging is printing out the values that it is comparing:

I ran the following with no problems:

You might want to check to make sure that the score you're working with is the value taht you are expecting.
 
SRI KUMAR
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for your help Mr.McNary
It works perfectly now
Kumar
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic