Hello
I have an application that need to round some values, with a normal symetric round, but the options available in the round function doesn't allow me to do this kind of round.
For example, if i have
vb.net Code:
?Math.Round(0.275,2) 0.28 ?Math.Round(1.275,2) 1.27 ?Math.Round(1.275,2,MidpointRounding.AwayFromZero) 1.27 ?Math.Round(1.275,2,MidpointRounding.ToEven) 1.27
The only way that looks like that i have a symmetric round it's when i use the format function:
vb.net Code:
?Format(0.275,"N2") "0.28" ?Format(1.275,"N2") "1.28"
I read some info available at msdn, i understand the bankers round technique, but when using the midpoint rounding the round should be ok, and it isn't. I'm missing something here?
Can i use the Format function and by using the Nx string, i have a symmetric rounding always?
Thanks
Meanwhile i have this function to do the job:
vb.net Code:
Public Function MyRound(ByVal valor As Decimal, ByVal casasDecimais As Integer) As Decimal Dim sinal As Integer = Math.Sign(valor) Dim escala As Decimal = Math.Pow(10, casasDecimais) Dim arredondado As Decimal = Math.Floor(Math.Abs(valor) * escala + 0.5D) Return ((sinal * arredondado) / escala) End Function




Rate People That Helped You
Reply With Quote