Results 1 to 5 of 5

Thread: Help with currency conversions.

  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    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?

  2. #2
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help with currency conversions.

    You would have to show some code

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2012
    Posts
    2

    Re: Help with currency conversions.

    Do you not see the pastebin? -.-



    http://pastebin.com/KgzjmRMP

  4. #4
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    110,297

    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:
    1. 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:
    1. ResultListBox.Items.Add(String.Format("INCOME: {0:c}   TAX: {1:c}", IncomeTxtBox.Text, TAX))
    The "c" format specifier will produce currency format.

  5. #5
    PowerPoster
    Join Date
    Feb 2012
    Location
    West Virginia
    Posts
    14,205

    Re: Help with currency conversions.

    Quote Originally Posted by MODNAR View Post
    Do you not see the pastebin? -.-



    http://pastebin.com/KgzjmRMP
    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
  •  



Click Here to Expand Forum to Full Width