Funcao - strzero |
Top Previous Next |
// Funcao STRZERO
function StrZero(const valor: Real; const tamanho:Integer; decimais: Integer=0): String; begin Result := StrTran(Format('%.' + IntToStr(decimais) + 'f', [valor]), '-', ''); Result := Replicate('0', tamanho - Length(Result)) + Result; end;
function StrZero2(const valor: Real; const tamanho:Integer; decimais: Integer=0; RemoveNegativo : Boolean = False): String; begin Result := StrTran(Format('%.' + IntToStr(decimais) + 'f', [valor]), '-', ''); Result := Replicate('0', Tamanho - Length(Result)) + Result;
if (not RemoveNegativo) and (Valor < 0) then Result := '-' + Copy(Result,2,Length(Result)); end;
// Se for somente para inteiros pode-se usar:
function StrZero(const Valor, Tamanho: Integer): string; begin Result := Format('%.' + IntToStr(Tamanho) + 'd',[Valor]); end;
|