Home > Mobile >  Round Down Value Using VB.net
Round Down Value Using VB.net

Time:08-13

Can anyone give me some help on how to round down in Visual Basic? I need 1.235 to be converted to 1.23 and NOT 1.24.

CodePudding user response:

What is in the comments,

    Const numD As Integer = 100 'for 3 digits 1000, etc.
    Dim d As Double = 1.235#
    Dim d1 As Double
    d1 = Math.Round(d, 2)
    Stop
    d1 = Math.Round(d, 2, MidpointRounding.AwayFromZero)
    Stop
    d1 = Math.Round(d, 2, MidpointRounding.ToEven)
    Stop
    d1 = Math.Sign(d) * Math.Floor(Math.Abs(d) * numD) / numD 'winner winner
    Stop

CodePudding user response:

Dim value As double = 1.235
value = Math.Floor(value * 100) / 100
  • Related