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:
  1. ?Math.Round(0.275,2)
  2. 0.28
  3. ?Math.Round(1.275,2)
  4. 1.27
  5. ?Math.Round(1.275,2,MidpointRounding.AwayFromZero)
  6. 1.27
  7. ?Math.Round(1.275,2,MidpointRounding.ToEven)
  8. 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:
  1. ?Format(0.275,"N2")
  2. "0.28"
  3. ?Format(1.275,"N2")
  4. "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:
  1. Public Function MyRound(ByVal valor As Decimal, ByVal casasDecimais As Integer) As Decimal
  2.         Dim sinal As Integer = Math.Sign(valor)
  3.         Dim escala As Decimal = Math.Pow(10, casasDecimais)
  4.         Dim arredondado As Decimal = Math.Floor(Math.Abs(valor) * escala + 0.5D)
  5.         Return ((sinal * arredondado) / escala)
  6.     End Function