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

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

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
Asked:
dizzycat
1 Solution
 
srikanthreddyn143Commented:
0
 
Reza RadCommented:
Math.Truncate(6.8474556 * 100) / 100
0
 
dizzycatAuthor 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
VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

 
bhmahlerCommented:
myNumber.ToString("0.00")
0
 
dizzycatAuthor Commented:
dosent work!
0
 
srikanthreddyn143Commented:
mynumber.tostring("#.##")
0
 
dizzycatAuthor Commented:
dosent work!
0
 
srikanthreddyn143Commented:
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
 
VBRocksCommented:
Do it like this:

        Dim mynumber As String = "6.8474556"

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

        MsgBox(number)


0

Featured Post

Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

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