[Okta Webinar] Learn how to a build a cloud-first strategyRegister Now

x
• Status: Solved
• Priority: Medium
• Security: Public
• Views: 465

# format decimal

Hi experts

Would someone show me how to convert a decimal number so that it has only 2 places to the right of the decimal point IE:

6.8474556 to 6.84
0
dizzycat
1 Solution

Commented:
0

Commented:
Math.Truncate(6.8474556 * 100) / 100
0

Author Commented:
Still no luck
This is my code:

Dim mynumber as string = TextBox1.text
If mynumber = CDec(TextBox1.Text)Then
<<<< need code here to trim the decimal so that it has only 2 places to the right of decimal point>>>>>>>
Label1.Text = mynumber
end if

0

Commented:
myNumber.ToString("0.00")
0

Author Commented:
dosent work!
0

Commented:
mynumber.tostring("#.##")
0

Author Commented:
dosent work!
0

Commented:
Sorry that doesnt work because mynumber is of type string.

this should work

Dim der As String = "123.4567"
Dim derarr() As String = der.Split(".")
If derarr(1).Length > 2 Then
der = der.Remove(der.Length - 2, 2)
End If
0

Commented:
Do it like this:

Dim mynumber As String = "6.8474556"

Dim number As String = CDec(mynumber).ToString("######.00")

MsgBox(number)

0

## Featured Post

Tackle projects and never again get stuck behind a technical roadblock.