Click to See Complete Forum and Search --> : Formatting Numbers in VB


mizer
May 12th, 2005, 01:39 PM
I have a question, I have user entering in numbers on a form into a text box. Say the user enters 500.00 in one textbox and 510.00 in another. Now I want to add the numbers together and I want the output to look like $1,010.00. I do I get the output to have the thousands separator if the total is calls for one?

Thanks in advance

DSJ
May 12th, 2005, 02:29 PM
Dim Dec As Decimal = 1010.00
MsgBox(Dec.ToString("$###,###.#0"))

mizer
May 12th, 2005, 03:30 PM
Does the format have to be in quotes?

mizer
May 13th, 2005, 01:03 PM
Ok new problem. When I read in the text from a textbox and do Decimal.Parse(TheTextbox.text), it take what ever number is there (ex: 2.00) and converts it to 2D. I need it to stay at 2.00 or 5.14 or whatever the user enters. How do I get around this problem?

mizer
May 13th, 2005, 01:29 PM
More info, this is the code I am trying to get to work.

TheNumber = Decimal.Parse(TempString)
TheNumber = Decimal.Round(TheNumber, 2)
TheTextBox.Text = TheNumber.ToString("$###,###.##")

This works great except when the user enters 0.00 or 2.00, 13.00, etc..anything that ends in .00 is causing and issue. If its 2.00 it just displays 2 and if its 0.00 it completely blows up. Any ideas would be appreciated.

DSJ
May 13th, 2005, 01:41 PM
Change "$###,###.##" to "$###,###.#0"