Fórum como saber se ha resto em um divisão de numeros fracionarios #253300

04/10/2004

0

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

Responder

Posts

04/10/2004

Dimas

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


Responder

Gostei + 0

05/10/2004

Aroldo Zanela

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;



Responder

Gostei + 0

05/10/2004

Adilsond

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;



Responder

Gostei + 0

06/10/2004

Aroldo Zanela

Colega,

Bem lembrado. :oops:


Responder

Gostei + 0

Utilizamos cookies para fornecer uma melhor experiência para nossos usuários, consulte nossa política de privacidade.

Aceitar