On 27 Sep, 15:11, eric.steigerw...@va.gov wrote:
Can anyone offer any help with this ? I have the following code :
DecimalFormat df = new DecimalFormat("0.00");
mrate = show_student_awards.getString("monthly_rate");
double dollar = Double.parseDouble(mrate);
double dollar2 = df.format(dollar);
the code runs up to the point where I attempt to do the format. There
it returns an error saying that it expects a double, and found a
string. The data in the resultset (show_student_awards) is in the SQL
2005 database as a currency data type. I've also tried retrieving it
as a double, but get the same result. Java just won't seem to convert
it to a double.
Thanks.
Eric
I presume that you define mrate somewhere as String too. If so, there
is NO way the error is where you say it is...
Working backwards logically:
1) your error message "it returns an error saying that it expects a
double, and found a string" means that you are trying to assign string
to variable defined as double. The ONLY place where I can see you
doing that is on line mrate =
show_student_awards.getString("monthly_rate"); mrate here is not
defined, but I presume it is a string.
2) that means your mrate is defined as double.
problem solved...
But not the fundamental problem.
Do not use double for monetary values.