473,624 Members | 2,612 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

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 DefaultListMode l. When I use
getText() on the field I pass it to Double.parseDou ble 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 12284

"Brandon McCombs" <bm******@ma.rr .com> wrote in message
news:42******** *******@ma.rr.c om...
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 DefaultListMode l. When I use
getText() on the field I pass it to Double.parseDou ble 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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

10
1910
by: Jacek Dziedzic | last post by:
Hi! Let's say I have a class called Triplet that serves as an envelope for double, ie. class Triplet { public: Triplet() {/*...*/} /* some things that double doesn't have, like
16
3827
by: ferran | last post by:
How can I cast from (long double*) to (const double*) I have tried: const double* Value1 = (const double*)Value2; The compiler does not complain but the actual results when I access the const double* are incorrect. Note that the (long double*) is a pointer to an array of long doubles.
6
12352
by: Todd Shillam | last post by:
I'm a total C++ newbie here--my background is largely in Visual Basic. I'm looking for someone who knows (or can send me in the right direction) on a method to convert a double to currency for output; moreover, I'm interested in finding a method that supports the thousandths separator. I have found a money class that works just fine; however, it doesn't include the thousandths separator. Any assistance would be greatly appreciated. ...
1
5798
by: ACaunter | last post by:
Hi all, I was wondering if there was a way to convert a double value to currency. sometimes the double number is: 7 or 7.7 or 7.77 or 7.776543 I needed to always get a decimal and 2 digits after the decimal for every answer. thanks -- AdamPC@hotmail.com
3
13948
by: Web learner | last post by:
The following code works fine private List<double> GetDataFor(string column, int selectedYear) { ------- ------- return list; } foreach (double item in GetDataFor("AirTemp", selectedYear)) { Response.Write(item.ToString() + ", ");
1
7984
by: krishna81m | last post by:
I am a newbie and have been trying to understand conversion from double to int and then back to int using the following code was posted on the c++ google group. Could someone help me out with understanding why and how a double can be represented in bits and bytes and which of the following can allow us to view the binary representation, unsigned char representation and then convert back to int please... #include<iostream> #include<iomanip>...
0
8182
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
8688
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
8352
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
1
6115
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5570
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4085
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
2614
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
1
1800
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
2
1496
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.