SQLRound (rtl)

De Wiki1000
Function SQLRound(D:Double; len:Integer):Double;

Cette fonction arrondie un nombre flottant suivant la même syntaxe que la fonction SQL ROUND.

Result Valeur arrondie.
D Valeur à arrondir
len Spécificateur de longueur.

Exemple

Implémentation de SQLRound

function SQLRound(f:double; len:Integer):double;
const fac:Array[0..8] of Extended = (1,10,100,1000,10000,100000,1000000,10000000,100000000);
begin
  //ROUND(748.58,-4)= 0
  //ROUND(748.58,-1)= 750.00
  //ROUND(748.58,-2)= 700.00
  //ROUND(748.58,-3)= 1000.00
  //ROUND(123.9994,3)= 123.9990
  //ROUND(123.9995,3)= 124.0000
  //
  if (len>=0) then
   begin
     if len>8 then len := 8;
     Result := Round(f*fac[len])/fac[len];
   end
   else
   begin
     len := -1*len;
     if len>8 then len := 8;
     Result := Round(f/fac[len])*fac[len];
   end;
end;

Voir aussi:

Développement DSMDéveloppement DSM





Whos here now:   Members 0   Guests 0   Bots & Crawlers 1
 
Outils personnels