File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes Beginning Java and the fly likes validations problems(decimal value check?) Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Beginning Java
Bookmark "validations problems(decimal value check?)" Watch "validations problems(decimal value check?)" New topic
Author

validations problems(decimal value check?)

SRI KUMAR
Greenhorn

Joined: Jul 15, 2003
Posts: 3
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

Joined: Nov 04, 2001
Posts: 1871
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

Joined: Aug 20, 2001
Posts: 1815
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.


Piscis Babelis est parvus, flavus, et hiridicus, et est probabiliter insolitissima raritas in toto mundo.
SRI KUMAR
Greenhorn

Joined: Jul 15, 2003
Posts: 3
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

Joined: Aug 20, 2001
Posts: 1815
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

Joined: Jul 15, 2003
Posts: 3
Thanks for your help Mr.McNary
It works perfectly now
Kumar
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: validations problems(decimal value check?)
 
Similar Threads
Quick question about new object
TestScores
ArrayList Use Question
Decimals not converting to correct fractions
TestScores