Tema: Redondeo
Ver Mensaje Individual
  #19  
Antiguo 04-04-2014
Avatar de ecfisa
ecfisa ecfisa is offline
Moderador
 
Registrado: dic 2005
Ubicación: Tres Arroyos, Argentina
Posts: 10.508
Reputación: 36
ecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to beholdecfisa is a splendid one to behold
Hola novato_erik.

Tanto Delphi como Firebird, redondean (y lo hacen muy bién) con SimpleRoundTo() y ROUND(), pero si sos de los que te gusta ir a las bases, te pongo otra opcion.

Delphi:
Código Delphi [-]
function Redondear(const Numero: Double; const Digitos: Integer): Double;
var
  Factor: Double;
begin
  Factor:= Abs(Exp(Ln(10)*(-Digitos)));
  Result:= Trunc((Numero/Factor) + 0.5) * Factor;
end;

Firebird:
Código SQL [-]
SET TERM ^ ;

CREATE OR ALTER PROCEDURE SP_ROUND(NUMERO DOUBLE PRECISION, DIGITOS INTEGER)
RETURNS(RESULT DOUBLE PRECISION)
AS
  DECLARE VARIABLE FACTOR DOUBLE PRECISION;
BEGIN
  FACTOR = ABS(EXP(LN(10)*(-DIGITOS)));
  RESULT = TRUNC((NUMERO/FACTOR)+0.5)*FACTOR;
  SUSPEND;
END^

SET TERM ; ^

Saludos
__________________
Daniel Didriksen

Guía de estilo - Uso de las etiquetas - La otra guía de estilo ....
Responder Con Cita