Ver Mensaje Individual
  #2  
Antiguo 28-04-2005
TheRafa TheRafa is offline
Miembro
 
Registrado: abr 2005
Posts: 24
Reputación: 0
TheRafa Va por buen camino
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;
Responder Con Cita