locked
restrict decimal RRS feed

  • Question

  • User-454568543 posted

     How to allow two numbers after decimal points

    anand

    Thursday, September 24, 2009 5:20 AM

Answers

  • User-952121411 posted

     There are a few ways to do this.  Take a look at the code below:

    'Using String Format of "F2"
    Dim Dec As Decimal = 2.45653
    Dim Num As String = Dec.ToString("F2")
     
    'Using 'FormatNumber':
    Dim Dec As Decimal = 2.45653
    Dim Num As String = FormatNumber(Dec, 2, TriState.UseDefault, GroupDigits:=TriState.False)
    'Using Math.Round; notice remains type of Decimal
    Dim Dec As Decimal = Math.Round(2.45653, 2)
    'And of coarse, for any of these that change to a string, you can parse back into a Decimal like below
    Dec = Decimal.Parse(Num)



     

    • Marked as answer by Anonymous Thursday, October 7, 2021 12:00 AM
    Thursday, September 24, 2009 9:52 AM