Math.Round does not always show two decimal places

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Ricky71
    New Member
    • Oct 2008
    • 2

    Math.Round does not always show two decimal places

    I'm writing a program in vb.net 2008 that calculates grades and puts them in a list. When I use Math.Round it will not show two decimal places for a number without decimals. For example:

    This is what I have

    100
    96.97
    93.94
    ...

    Is there a way to force 100 or any other number that does not have decimals to have .00 after it?

    Here is what I'm using in my code now

    Str(Math.Round( i + HighGrade, 2, MidpointRoundin g.AwayFromZero) ).PadLeft(4)
  • Curtis Rutland
    Recognized Expert Specialist
    • Apr 2008
    • 3264

    #2
    Use String.Format. Check this page for how to use it. Scroll down a little bit.

    Comment

    • Ricky71
      New Member
      • Oct 2008
      • 2

      #3
      Thank you so much!
      It worked.

      If anyone else has this problem, this is what I changed:

      String.Format(" {0:#.00}", Math.Round(i + HighGrade, 2, MidpointRoundin g.AwayFromZero) ).PadLeft(4)

      After String.Format use this "{0:#.00}" and replace the number of 0's after the decimal to what you need.

      Comment

      Working...