Results 1 to 8 of 8

Thread: Very Easy Question on Decimal Numbers

  1. #1

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    86

    Very Easy Question on Decimal Numbers

    Hi there,

    From my program output i get a number like:

    74474.3498393431

    I want to show the first three digits after the dot. How can I do it please?

    Thank you.

    WebServant

  2. #2
    Raging swede Atheist's Avatar
    Join Date
    Aug 2005
    Location
    Sweden
    Posts
    8,018

    Re: Very Easy Question on Decimal Numbers

    use the math namespace to round the value

    VB Code:
    1. math.Round(74474.3498393431, 3)

    Will give you 3 numbers after the decimal
    Rate posts that helped you. I do not reply to PM's with coding questions.
    How to Get Your Questions Answered
    Current project: tunaOS
    Me on.. BitBucket, Google Code, Github (pretty empty)

  3. #3
    Addicted Member
    Join Date
    Jan 2002
    Location
    West Virginia
    Posts
    193

    Re: Very Easy Question on Decimal Numbers

    Using Format
    VB Code:
    1. Format(74474.3498393431, "####.###")
    2. gives 74474.35 (rounds)
    to assure 3 places always
    VB Code:
    1. Format(74474.3498393431, "####.000")
    2. gives 74474.350

  4. #4

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    86

    Re: Very Easy Question on Decimal Numbers

    i have this:

    ERLCalc = 0.0
    R = DCV
    For i = 0 To tblCustomData.Rows.Count - 1
    If tblCustomData.Rows(i)("CompleteTrax") <> 1 Then
    If (tblCustomData.Rows(i)("CompleteTrax")) <> 99999 Then
    LF = (30.0 - tblCustomData.Rows(i)("CompleteTrax") - 1.0) / 30.0
    DF = Math.Pow(1.0 / (1.0 + R), tblCustomData.Rows(i)("CompleteTrax") - 1.0)
    Else
    LF = (1.0 / 30.0)
    DF = Math.Pow(1.0 / (1.0 + R), 29.0)
    End If
    ERLCalc = ERLCalc + tblCustomData.Rows(i)("Length") * DF * LF

    End If
    Next
    Return ERLCalc

    Then this:

    txtERL.Text = objLogic.dblERLCalc.ToString()


    How can Iround it please?

  5. #5
    Addicted Member
    Join Date
    Jan 2002
    Location
    West Virginia
    Posts
    193

    Re: Very Easy Question on Decimal Numbers

    Either of the methods above:

    VB Code:
    1. txtERL.Text = math.Round(objLogic.dblERLCalc.ToString(),3)
    or

    VB Code:
    1. txtERL.Text = Format(objLogic.dblERLCalc,"####.000")

  6. #6
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Very Easy Question on Decimal Numbers

    If you want to actually change the value of the number then use Math.Round. If you want to leave the actual number unaffected but display a string representation then use ToString("f3"), which means a fixed-point number with three decimal places. If you want thousand separators then use "n3" instead.

    Numeric Format Strings
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  7. #7

    Thread Starter
    Lively Member
    Join Date
    Jul 2006
    Posts
    86

    Re: Very Easy Question on Decimal Numbers

    Worked perfectly. Thanks all!

  8. #8
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: Very Easy Question on Decimal Numbers

    Don't forget to resolve your thread from the Thread Tools menu.
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width