470,870 Members | 1,506 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 470,870 developers. It's quick & easy.

double to currency and currency to double

hello,

I have an app that pops up a custom dialog box and one of the fields for
user input is an account balance field. The data gets put into an
Object and eventually into an instance of DefaultListModel. When I use
getText() on the field I pass it to Double.parseDouble to convert it so
I can store it as a number and not a string. When I display it (either
in the list or in the dialog box) I want it to be displayed using
currency format and I display it in my list using toString() along with
other fields. I just concatenate all of them together and return them
in the toString() method. All that works fine but I run into trouble
when a file that I read data from already has the balance field in
currency format because I can't figure out how to read the value
correctly to turn it back into just a double to be stored in my balance
field. I can convert it into a String but using parseDouble on it
doesn't work and I'm guessing it is because of the $ and , in the
String.

any ideas?

thanks

Jul 18 '05 #1
1 12100

"Brandon McCombs" <bm******@ma.rr.com> wrote in message
news:42***************@ma.rr.com...
hello,

I have an app that pops up a custom dialog box and one of the fields for
user input is an account balance field. The data gets put into an
Object and eventually into an instance of DefaultListModel. When I use
getText() on the field I pass it to Double.parseDouble to convert it so
I can store it as a number and not a string. When I display it (either
in the list or in the dialog box) I want it to be displayed using
currency format and I display it in my list using toString() along with
other fields. I just concatenate all of them together and return them
in the toString() method. All that works fine but I run into trouble
when a file that I read data from already has the balance field in
currency format because I can't figure out how to read the value
correctly to turn it back into just a double to be stored in my balance
field. I can convert it into a String but using parseDouble on it
doesn't work and I'm guessing it is because of the $ and , in the
String.

any ideas?


here's an idea:
Change the account balance field to numeric type and
write the double values to file instead of the currency formatted string.
otherwise, you'll have to use use string methods to remove $ and commas from
the string before parsing to double.
Jul 18 '05 #2

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

10 posts views Thread by Jacek Dziedzic | last post: by
16 posts views Thread by ferran | last post: by
6 posts views Thread by Todd Shillam | last post: by
1 post views Thread by ACaunter | last post: by
3 posts views Thread by Web learner | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.