Arredondamento

Delphi

15/08/2008

Ola,

Quando eu tiver um valor fracionado gostaria de arredondar sempre para o próximo valor decimal, tipo:


5,32 para 6
10,56 para 11
16,01 para 17
20,09 para 21

e assim por diante ????


Steve_narancic

Steve_narancic

Curtidas 0

Respostas

Steve_narancic

Steve_narancic

15/08/2008

resolvi assim:
var
  x, y: Real;
begin

   x:= StrToFloat(Edit1.Text);
   y:= StrToFloat(Edit2.Text);


   if (x / y) > Trunc(x / y) then
     caption:=  FloatToStr(Trunc(x / y)+ 1)
   else
      caption:=  FloatToStr(roundto((x / y),-2));



end;



GOSTEI 0
Marco Salles

Marco Salles

15/08/2008

resolvi assim: Código:
var 
  x, y: Real; 
begin 

   x:= StrToFloat(Edit1.Text); 
   y:= StrToFloat(Edit2.Text); 


   if (x / y) > Trunc(x / y) then 
     caption:=  FloatToStr(Trunc(x / y)+ 1) 
   else 
      caption:=  FloatToStr(roundto((x / y),-2)); 
end;


É so Truncar e adicinar mais Um

X:=Trunc(x)+1;



GOSTEI 0
POSTAR