153 lines
3.9 KiB
ObjectPascal
153 lines
3.9 KiB
ObjectPascal
|
|
{
|
|||
|
|
===============================================================================
|
|||
|
|
Copyright (<EFBFBD>) 2002. Rodax Software.
|
|||
|
|
===============================================================================
|
|||
|
|
Los contenidos de este fichero son propiedad de Rodax Software titular del
|
|||
|
|
copyright. Este fichero s<EFBFBD>lo podr<EFBFBD> ser copiado, distribuido y utilizado,
|
|||
|
|
en su totalidad o en parte, con el permiso escrito de Rodax Software, o de
|
|||
|
|
acuerdo con los t<EFBFBD>rminos y condiciones establecidas en el acuerdo/contrato
|
|||
|
|
bajo el que se suministra.
|
|||
|
|
-----------------------------------------------------------------------------
|
|||
|
|
Web: www.rodax-software.com
|
|||
|
|
===============================================================================
|
|||
|
|
Fecha primera versi<EFBFBD>n: 01-11-2002
|
|||
|
|
Versi<EFBFBD>n actual: 1.0.0
|
|||
|
|
Fecha versi<EFBFBD>n actual: 01-11-2002
|
|||
|
|
===============================================================================
|
|||
|
|
Modificaciones:
|
|||
|
|
|
|||
|
|
Fecha Comentarios
|
|||
|
|
---------------------------------------------------------------------------
|
|||
|
|
===============================================================================
|
|||
|
|
}
|
|||
|
|
|
|||
|
|
unit NumFunc;
|
|||
|
|
|
|||
|
|
interface
|
|||
|
|
|
|||
|
|
{ Funciones num<75>ricas }
|
|||
|
|
function ValidarIVA (IVA : String) : Boolean;
|
|||
|
|
function ValidarDto (Dto : String) : Boolean;
|
|||
|
|
function Redondear(x : Extended; d : Integer) : Extended;
|
|||
|
|
function EsNumerico(Cadena: String) : Boolean;
|
|||
|
|
function EsInteger(Codigo: String) : Boolean;
|
|||
|
|
function EsSmallInt(Codigo: String) : Boolean;
|
|||
|
|
|
|||
|
|
function darPorcentaje(x1, x2: Double): Double;
|
|||
|
|
|
|||
|
|
implementation
|
|||
|
|
|
|||
|
|
uses
|
|||
|
|
Math, SysUtils, StrFunc;
|
|||
|
|
|
|||
|
|
resourcestring
|
|||
|
|
msgRangoNoValido = '%s no es un valor v<>lido. Debe estar en el rango de 0 a 100.';
|
|||
|
|
msgDtoNoValido = '%s no es un descuento v<>lido.';
|
|||
|
|
msgIVANoValido = '%s no es un valor para el IVA v<>lido.';
|
|||
|
|
|
|||
|
|
function Redondear(x : Extended; d : Integer) : Extended;
|
|||
|
|
// Redondear(123.456, 0) = 123.00
|
|||
|
|
// Redondear(123.456, 2) = 123.46
|
|||
|
|
// Redondear(123456, -3) = 123000
|
|||
|
|
var
|
|||
|
|
n: Extended;
|
|||
|
|
begin
|
|||
|
|
n := Power(10, d);
|
|||
|
|
x := x * n;
|
|||
|
|
Result := (Int(x) + Int(Frac(x) * 2)) / n;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function EsNumerico(Cadena: String) : Boolean;
|
|||
|
|
var
|
|||
|
|
Codigo: Integer;
|
|||
|
|
Valor: Double;
|
|||
|
|
begin
|
|||
|
|
Val(Cadena, Valor, Codigo);
|
|||
|
|
Result := (Codigo = 0)
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function EsInteger(Codigo: String) : Boolean;
|
|||
|
|
begin
|
|||
|
|
//Comprueba que le numero es lo sufucientemente peque<75>o para ser un entero
|
|||
|
|
try
|
|||
|
|
Result:=True;
|
|||
|
|
StrToInt(Codigo);
|
|||
|
|
except
|
|||
|
|
on E : EConvertError do begin
|
|||
|
|
Result:=False;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function EsSmallInt(Codigo: String) : Boolean;
|
|||
|
|
begin
|
|||
|
|
//Comprueba que le numero es lo sufucientemente peque<75>o para ser un entero
|
|||
|
|
try
|
|||
|
|
Result:=(StrToInt(Codigo)<High(SmallInt));
|
|||
|
|
except
|
|||
|
|
on E : EConvertError do begin
|
|||
|
|
Result:=False;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function validarIVA (IVA : String) : Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
if (EsCadenaVacia(IVA)) then
|
|||
|
|
begin
|
|||
|
|
Result := True;
|
|||
|
|
exit;
|
|||
|
|
end;
|
|||
|
|
try
|
|||
|
|
if (StrToFloat(IVA) < 0) or (StrToFloat(IVA) > 100) then
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
raise ERangeError.CreateFmt(msgRangoNoValido, [IVA]);
|
|||
|
|
end;
|
|||
|
|
Result := True;
|
|||
|
|
except
|
|||
|
|
on E : EConvertError do
|
|||
|
|
raise EConvertError.CreateFmt(msgIVANoValido, [IVA]);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function validarDto (Dto : String) : Boolean;
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
if (EsCadenaVacia(Dto)) then
|
|||
|
|
begin
|
|||
|
|
Result := True;
|
|||
|
|
exit;
|
|||
|
|
end;
|
|||
|
|
try
|
|||
|
|
if (StrToFloat(Dto) < 0) or (StrToFloat(Dto) > 100) then
|
|||
|
|
begin
|
|||
|
|
Result := False;
|
|||
|
|
raise ERangeError.CreateFmt(msgRangoNoValido, [Dto]);
|
|||
|
|
end;
|
|||
|
|
Result := True;
|
|||
|
|
except
|
|||
|
|
on E : EConvertError do
|
|||
|
|
raise EConvertError.CreateFmt(msgDtoNoValido, [Dto]);
|
|||
|
|
end;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
function darPorcentaje(x1, x2: Double): Double;
|
|||
|
|
//Formula
|
|||
|
|
//x1 --- 100
|
|||
|
|
//x2 --- X
|
|||
|
|
//X = (x2 * 100)/x1
|
|||
|
|
var
|
|||
|
|
Aux: Double;
|
|||
|
|
|
|||
|
|
begin
|
|||
|
|
Aux := x2 * 100;
|
|||
|
|
if (x1 = 0)
|
|||
|
|
then Aux := -1
|
|||
|
|
else Aux := (Aux / x1);
|
|||
|
|
Result := Aux;
|
|||
|
|
end;
|
|||
|
|
|
|||
|
|
end.
|