Foros Club Delphi

Foros Club Delphi (https://www.clubdelphi.com/foros/index.php)
-   Trucos (https://www.clubdelphi.com/foros/forumdisplay.php?f=52)
-   -   Poner puntos a los números mayores de 999 y hasta 1M (https://www.clubdelphi.com/foros/showthread.php?t=80848)

Pedro-Juan 08-12-2007 02:22:25

Poner puntos a los números mayores de 999 y hasta 1M
 
//Formatea cadenas de números hasta 1 millón
//Seguro que podeís mejorarla, eso si no existe en delphi...

//LO SIENTO, NO ACIERTO A MOSTRARLA CON LAS ETIQUETAS

Llamada:

Delphi [-]
Form1.label1.Caption := FormatIntMax_1M(nCantidad);

Delphi [-]
function FormatIntMax_1M(Cad: Integer): String; Formatea hasta 1 millón
var CadFormat, CadResul: String;
i: Integer;
begin
CadFormat := Trim(IntToStr(Cad));
CadResul := '';
i := 1;
//Cantidades Entre 0 y 999
if (Length(CadFormat) < 4) then Result := CadFormat; //La deja como está
//Cantidades Entre 1.000 y 9.999
if (Length(CadFormat) = 4) then begin
while (i < 5) do begin
if (i = 1) then begin
CadResul := CadResul + Copy(CadFormat,i,1);
CadResul := (CadResul + '.');
end
else begin
CadResul := (CadResul + Copy(CadFormat,i,1));
end;
i := (i + 1)
end;
Result := CadResul;
end;
//Cantidades Entre 10.000 y 99.999
if (Length(CadFormat) = 5) then begin
while (i < 6) do begin
if (i = 2) then begin
CadResul := CadResul + Copy(CadFormat,i,1);
CadResul := (CadResul + '.');
end
else begin
CadResul := (CadResul + Copy(CadFormat,i,1));
end;
i := (i + 1)
end;
Result := CadResul;
end;
//Cantidades Entre 100.000 y 999.999
if (Length(CadFormat) = 6) then begin
while (i < 7) do begin
if (i = 3) then begin
CadResul := CadResul + Copy(CadFormat,i,1);
CadResul := (CadResul + '.');
end
else begin
CadResul := (CadResul + Copy(CadFormat,i,1));
end;
i := (i + 1)
end;
Result := CadResul;
end;
end;

Khronos 08-12-2007 16:23:24

No hace falta todo eso para poner el punto de los miles. Con esto te llega:

Código Delphi [-]
 edit1.text:=FormatFloat('#,', strtoint(edit1.text));

//En el edit pones un numero mayor de 999

Salu2

javier7ar 26-12-2007 19:13:08

es verdad, yo uso FormatFloat('#,##0.00',Valor_Decimal) que te pone los dos decimales tambien aparte del separador de miles


La franja horaria es GMT +2. Ahora son las 16:57:46.

Powered by vBulletin® Version 3.6.8
Copyright ©2000 - 2024, Jelsoft Enterprises Ltd.
Traducción al castellano por el equipo de moderadores del Club Delphi