Results 1 to 2 of 2

Thread: [02/03] Decimal

  1. #1

    Thread Starter
    Hyperactive Member ahmad_iam's Avatar
    Join Date
    Jun 2005

    Lightbulb [02/03] Decimal

    Suppose I am using a double variable for storing the grade point average. I want that there are two digit after the decimal point. How we can do.

    Imran Ahmad Mughal
    "Visual Studio .NET 2005/.NET Framework 2.0"

    The eyes are the greatest telescopes, one will ever need to study the universe. Let the heart be the tripod, the mind be the shaft, then let the eyes become the lens of that great telescope of which God gave to us all.

  2. #2
    .NUT jmcilhinney's Avatar
    Join Date
    May 2005
    Sydney, Australia

    Re: [02/03] Decimal

    If you want to display a Double value as a string with two decimal places then you use:
    VB Code:
    1. myString = myDouble.ToString("n2")
    If you actually want to round the Double value itself to two decimal places then you'd use:
    VB Code:
    1. myDouble = Math.Round(myDouble, 2)
    Note that Math.Round uses the normal method to round the value up or down. If you actually want to truncate then it is a little more complex, but still not difficult.

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