Reputation: 19
Im using this code for formatting my textbox.
Public Function TextFormat(ByVal sString As String) As String
Dim num1 As Decimal
Try
num1 = Convert.ToDecimal(sString)
TextFormat = FormatNumber(num1, 2)
Return TextFormat
Catch
TextFormat = sString
End Try
End Function
-the problem is its rounding off the number i input .. sample
textbox.text = "5999.99" it displaying "6000.00" how can i disable the auto rounding off number . or is there any other code for formatting text? "###,###,###.##" << it should be like this
thanks
Upvotes: 0
Views: 5429
Reputation: 6452
use ToString Instead FormatNumber.
Public Function TextFormat(ByVal sString As String) As String
Dim num1 As Decimal
If Double.TryParse(sString, num1) Then
Return num1.ToString("G") ' or ToString("F2") or ToString("0.00")
Else
Return sString
End If
End Function
Upvotes: 2
Reputation: 2296
Try to use:
Dim number = Math.Truncate(CInt(textbox.text) * 1000) / 1000;
textbox.text = number.toString
Upvotes: 0