-
Feb 22nd, 2012, 11:50 PM
#1
Thread Starter
New Member
Help with currency conversions.
http://pastebin.com/KgzjmRMP
I need to convert TAX to currency before it prints. How do I go about doing this? The current code doesnt work for TAX but does for the incometxtbox.text
Any ideas?
-
Feb 23rd, 2012, 12:07 AM
#2
Re: Help with currency conversions.
You would have to show some code
-
Feb 23rd, 2012, 12:17 AM
#3
Thread Starter
New Member
Re: Help with currency conversions.
Do you not see the pastebin? -.-
http://pastebin.com/KgzjmRMP
-
Feb 23rd, 2012, 12:43 AM
#4
Re: Help with currency conversions.
Any particular reason that you chose to make us navigate to an external site (without actually saying "here's my code" or the like) rather than simply pasting it into your post so we could see everything together?
As for the question, a Double value is just a number. It isn't currency or not currency. It's just a number. When you call FormatCurrency it returns a String that contains your number formatted as currency. If you then assign that String back to your Double variable then the String must be converted back to just a number, which has no formatting.
It appears to work for the TextBox because the Text of a TextBox is a String, so your code is implicitly converting the original String to a Double, then formatting that as a new currency String. The way you've done it, that will fail if the user doesn't enter a valid value.
You should ONLY convert a number to a String when you need a String. In your case, that's here:
vb.net Code:
ResultListBox.Items.Add("INCOME: " & IncomeTxtBox.Text & " TAX: " & TAX)
(See what I did there, not making you go off somewhere else to see the code?)
The "most proper" way to do that would be to use String.Format:
vb.net Code:
ResultListBox.Items.Add(String.Format("INCOME: {0:c} TAX: {1:c}", IncomeTxtBox.Text, TAX))
The "c" format specifier will produce currency format.
-
Feb 23rd, 2012, 12:56 AM
#5
Re: Help with currency conversions.
Originally Posted by MODNAR
I saw an external link but I rarely click on these. It is a simple matter to post your code where we can see it without needing to naviagte to another website.
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|