Results 1 to 9 of 9

Thread: rounding with deciamals...

  1. #1

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98

    rounding with deciamals...

    Is there a way to round the number 15.50193475 to 15.50 instead of 15.5?

  2. #2
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    Yes. Here's a code snippet from a project I did in school.

    VB Code:
    1. pdblAverage = ToDouble(pdblGrade1 + pdblGrade2 + pdblGrade3) / 3
    2. psngAverage = System.Convert.ToSingle(pdblAverage)
    3. lblAverage.Text = psngAverage.ToString("##.00")

    its the ("##.00") at the end that dtermines how many decimals to extend the number to.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  3. #3

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    what will that do if i have a number that actually works like 15.645

  4. #4
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    It'll just turn it into 15.64. You want it to round to 15.65?
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  5. #5
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by Azkar
    what will that do if i have a number that actually works like 15.645
    Ancient chinese secret

  6. #6

    Thread Starter
    Lively Member
    Join Date
    May 2003
    Posts
    98
    Oh okay, i just want it to use a 0 for a place holder if its not 2 places after the decimal

  7. #7
    Addicted Member The Phoenix's Avatar
    Join Date
    Aug 2003
    Location
    With my wife
    Posts
    142
    After looking in the MSDN I found that this should work to round.

    VB Code:
    1. Round(15.50193475, 2)
    That should return 15.50

    If you use a variable:

    VB Code:
    1. dim MyNumber as double = 15.50193475
    2. Round(MyNumber, 2)

    I cant seem to find anything about actual rounding though. They always round to even. Like if its 16.345, it become 16.34 instead of 16.35.

    <EDIT>

    Right, the zeros are just placeholders.
    Take my love
    Take my land
    Take me where I cannot stand
    I don't care, I'm still free
    You can't take the sky from me...

  8. #8
    KrisSiegel.com Kasracer's Avatar
    Join Date
    Jul 2003
    Location
    USA, Maryland
    Posts
    4,985
    Originally posted by The Phoenix


    I cant seem to find anything about actual rounding though. They always round to even. Like if its 16.345, it become 16.34 instead of 16.35.
    If you're rounding to 2 decimal places, it will probably will only use those 2, so it just discards the 5

  9. #9
    Frenzied Member
    Join Date
    Oct 2002
    Location
    Gammapolis
    Posts
    1,474
    Maybe this thread helps, about rounding toward even.
    'Heading for the automatic overload'
    Marillion, Brave, The Great Escape, 1994

    'How will WE stand the FIRE TOMORROW?'
    Eloy, Silent Cries and Mighty Echoes, The Vision - Burning, 1979

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