Results 1 to 2 of 2

Thread: Rounding a number for limited decimals

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2006
    Location
    CANADA
    Posts
    2

    Rounding a number for limited decimals

    how can I write aevent procedure code to round a number to two decimals?
    I am wrighting something similer to this
    a=val(x)+val(Y)
    I Know in exel "Round,2" Makes a number to Two Decimals.

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

    Re: Rounding a number for limited decimals

    Use the Math.Round method, e.g.
    VB Code:
    1. Dim myDouble As Double = 1.23456789
    2.  
    3. myDouble = Math.Round(myDouble, 2)
    4. MessageBox.Show(myDouble.ToString()) 'Displays 1.23
    5.  
    6. myDouble = 9.87654321
    7.  
    8. myDouble = Math.Round(myDouble, 2)
    9. MessageBox.Show(myDouble.ToString()) 'Displays 9.88
    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