Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Formatting numbers

Status
Not open for further replies.

Kai77

Programmer
Jun 7, 2004
77
NL
I am getting numbers in my webapp like so for instance:

100.500

is there an easy way to get rid of none needed zeroes? so i am left with 100.5 only?
 
Code:
Dim MyPos As Double = 19.95

Dim MyNeg As Double = -19.95

Dim MyZero As Double = 0

Dim MyString As String = MyPos.ToString("$#,##0.00;($#,##0.00);Zero")

' In the U.S. English culture, MyString has the value: $19.95.

MyString = MyNeg.ToString("$#,##0.00;($#,##0.00);Zero")

' In the U.S. English culture, MyString has the value: ($19.95).
' The minus sign is omitted by default.

MyString = MyZero.ToString("$#,##0.00;($#,##0.00);Zero")

' In the U.S. English culture, MyString has the value: Zero.

The following example demonstrates custom number formatting.

Code:
Dim myDouble As Double = 1234567890
Dim myString As String = myDouble.ToString( "(###) ### - ####" )
' The value of myString is "(123) 456 – 7890".

Dim MyInt As Integer = 42
MyString = MyInt.ToString( "My Number " + ControlChars.Lf + "= #" )
' In the U.S. English culture, MyString has the value: 
' "My Number
' = 42".


Hope these help about formating numbers
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top