como saber se ha resto em um divisão de numeros fracionarios

Delphi

04/10/2004

como saber se ha resto em um divisão de numeros fracionarios

ex: 7 / 1,5 = 4,67 c/ resto > q 0
6 / 1,5 = 4,00 c/ resto = 0

preciso saber se o resto é maior q zero.

a função não serve por q ela é p/ numeros inteiros.


Dimas

Dimas

Curtidas 0

Respostas

Dimas

Dimas

04/10/2004

a função MOD não da certo. ela só serve p/ numeros inteiros.


GOSTEI 0
Aroldo Zanela

Aroldo Zanela

04/10/2004

Colega,

procedure TForm1.Button1Click(Sender: TObject);
begin
if HaResto( 7 / 1.5) then ShowMessage(´Sim´) else ShowMessage(´Não´);
if HaResto( 6 / 1.5) then ShowMessage(´Sim´) else ShowMessage(´Não´);
end;

function TForm1.HaResto(Valor: Extended): Boolean;
var Inteira: Integer;
begin
  Inteira := Trunc(Valor);
  Result  := Inteira <> Valor;
end;



GOSTEI 0
Adilsond

Adilsond

04/10/2004

Utilize a função Frac.

Frac returns the fractional part of a real number. Unit System Category arithmetic routines function Frac(X: Extended): Extended; Description The Frac function returns the fractional part of the argument X. X is a real-type expression. The result is the fractional part of X; that is, Frac(X) = X - Int(X).


procedure TForm1.Button1Click(Sender: TObject);
begin
  if Frac(7 / 1.5) > 0 then
     ShowMessage(´7 / 1.5 com resto´)
  else
     ShowMessage(´7 / 1.5 sem resto´);
  if Frac(6 / 1.5) > 0 then
     ShowMessage(´6 / 1.5 com resto´)
  else
     ShowMessage(´6 / 1.5 sem resto´);
end;



GOSTEI 0
Aroldo Zanela

Aroldo Zanela

04/10/2004

Colega,

Bem lembrado. :oops:


GOSTEI 0
POSTAR