FTP | CCD | Buscar | Trucos | Trabajo | Foros |
|
Registrarse | FAQ | Miembros | Calendario | Guía de estilo | Temas de Hoy |
|
Herramientas | Buscar en Tema | Desplegado |
#1
|
|||
|
|||
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; |
|
|
|