Mirror

Insert Zero converted number to text (Views: 10)

Problem/Question/Abstract:

When I convert number(0012) to text I take a result just number (12). How can i take a result of number with zeros?

Answer:

Solve 1:

function StrZero(AValue, ALength: integer): string;
begin
Result := FormatFloat(StringOfChar('0', ALength), AValue);
end;


Solve 2:

function FormatWithZero(const AValue, ALen: Integer): string;
begin
Result := Format('%.' + IntToStr(ALen) + 'd', [AValue]);
end;


<< Back to main page