Results 1 to 5 of 5

Thread: [RESOLVED] [2005] Rounding of Digits in a Double

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Resolved [RESOLVED] [2005] Rounding of Digits in a Double

    Hi,
    Is there a easier way of rounding of a double

    I use the following

    Code:
    dim test1 as double
    test1 = math.round(a*b, 2)
    thanks

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

    Re: [2005] Rounding of Digits in a Double

    That is THE way. It isn't exactly hard.
    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

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Rounding of Digits in a Double

    thanks;

    Is there an option like

    Code:
    test1 = (a * b).ToString.Format("0.00")

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

    Re: [2005] Rounding of Digits in a Double

    1. How is that easier?
    2. Your 'test1' variable is a Double, so why would you be converting a value that is already a Double to String? You'd only have to convert back again to a Double.

    If you actually want a string, like to display in a Label or whatever then you can use myDouble.ToString("n2") or myDouble.ToString("f2"), but only do that if you catually want a string. Don't convert things to strings and back again without a very good reason. If there's a simple way to do what you want with the value's original type then that's what you should do.
    Last edited by jmcilhinney; May 21st, 2007 at 05:36 AM.
    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

  5. #5

    Thread Starter
    Hyperactive Member
    Join Date
    Mar 2005
    Posts
    449

    Re: [2005] Rounding of Digits in a Double

    Thanks JMC for the clarification...

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