On 27 Sep, 15:11, eric.steigerw...@va.gov wrote:
> Can anyone offer any help with this ? I have the following code :
>
[quoted text clipped - 13 lines]
>
> 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...
Lew - 27 Sep 2007 15:51 GMT
> On 27 Sep, 15:11, eric.steigerw...@va.gov wrote:
>> Can anyone offer any help with this ? I have the following code :
[quoted text clipped - 26 lines]
> 2) that means your mrate is defined as double.
> problem solved...
But not the fundamental problem.
Do not use double for monetary values.

Signature
Lew
GArlington - 27 Sep 2007 15:51 GMT
> On 27 Sep, 15:11, eric.steigerw...@va.gov wrote:
>
[quoted text clipped - 27 lines]
> 2) that means your mrate is defined as double.
> problem solved...
Sorry, correction...
<your code>
...
double dollar2 = df.format(dollar);
</your code>
I should have spotted that!!!
Please see what is returned by DecimalFormat.format()
http://java.sun.com/j2se/1.4.2/docs/api/java/text/DecimalFormat.html
>Can anyone offer any help with this ? I have the following code :
>
[quoted text clipped - 5 lines]
>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, ..
Please always copy/paste errors and exceptions.
It also helps to create an SSCCE* that others can
use to compare the code and any errors.
* <http://www.physci.org/codes/sscce.html>
Here is an example of an SSCCE.
<sscce>
import java.text.DecimalFormat;
class TestDecimalFormat {
public static void main(String[] args) {
DecimalFormat df = new DecimalFormat("0.00");
String mrate = "4987.56";
double dollar = Double.parseDouble(mrate);
//double dollar2 = df.format(dollar);
String dollar2 = df.format(dollar);
System.out.println("Your bill is: $" + dollar2);
}
}
</sscce>
I'll leave it at that, but note that it is far better
to use the inbuilt power of Java to to some things,
and formatting currency is one of them.
Look into NumberFormat.getCurrencyInstance(Locale)
Sun pays its engineers big bucks to figure these
things out for us.
HTH

Signature
Andrew Thompson
http://www.athompson.info/andrew/
eric.steigerwald@va.gov - 27 Sep 2007 16:10 GMT
> eric.steigerw...@va.gov wrote:
> >Can anyone offer any help with this ? I have the following code :
[quoted text clipped - 44 lines]
>
> Message posted via JavaKB.comhttp://www.javakb.com/Uwe/Forums.aspx/java-general/200709/1
Thanks for all the help. Problem turned out to be the (dumb) mistake
of trying to use a double as the return of the format function,
instead of a string.
Eric
Lew - 27 Sep 2007 16:51 GMT
> Thanks for all the help. Problem turned out to be the (dumb) mistake
> of trying to use a double as the return of the format function,
> instead of a string.
Actually, the problem is in the use of double to represent monetary values.
Don't do that.

Signature
Lew
Andrew Thompson - 27 Sep 2007 16:59 GMT
>> Thanks for all the help. Problem turned out to be the (dumb) mistake
>> of trying to use a double as the return of the format function,
>> instead of a string.
>
>Actually, the problem is in the use of double to represent monetary values.
>Don't do that.
Agreed. I was so busy concentrating on the code
itself that it got to the point that I "could not see
the forest, for the trees".

Signature
Andrew Thompson
http://www.athompson.info/andrew/
>double dollar2 = df.format(dollar);
DecimalFormat.format eats a double and produces a String. You are
assuming it produce a double.

Signature
Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com