![]() |
![]() |
| Paypal | FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
|||||||
| Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
|
Herramientas | Buscar en Tema | Desplegado |
|
#2
|
|||
|
|||
|
Redondeo Matemático
Yo utilizo esta función ya que el redondeo del delphi funciona más o menos como tu dices, incluso un poco más raro ya que el cinco unas veces lo redondea hacia arriba y otras hacia abajo.
function Redondeo(Nro: Double; Dec: Integer): Double; var Cad, Cad1, Cad2: String; Signo, Aux: Double; begin try If Not CadenaVacia(FormatFloat('################.#########',Abs(Nro))) Then Begin If abs(Nro) = Nro Then Signo := 1 Else Signo := (-1); Aux := Abs(Nro*Power(10,Dec+1)); If scl(',',FloatToStr(Aux)) <> 0 Then Aux := StrToFloat(copy(FloatToStr(Aux),1,scl(',',FloatToStr(Aux))-1)); If Dch(FloatToStr(Aux),1) >= '5' Then Aux := Aux + 10; Aux := StrToFloat(copy(FloatToStr(Aux),1, length(FloatToStr(Aux))-1)); Redondeo := (Aux/Power(10,Dec))*signo; End Else Redondeo := 0; except Redondeo := 0; End; End; |
|
|
|