Search code examples
vb.netformattingsignificant-digits

Round number but keep exact digits


when I call this function like this Rounded(50.080, 3) Im getting "50.08" how can I force to keep the trailing zeros?

Public Function Rounded(ByVal Number, ByVal Decimals)
    Rounded = Int(Number * 10 ^ Decimals + 1 / 2) / 10 ^ Decimals
End Function

Solution

  • Dim RoundedString As String = FormatNumber(Rounded, Decimals, , , TriState.False)
    

    should do it for you