getstrfromint.inc 718 B

1234567891011121314151617181920212223242526272829303132333435363738
  1. if Width <= 0 then
  2. exit;
  3. NegSign := Val < 0;
  4. Val := Abs(Val);
  5. // we'll have to store characters backwards first
  6. I := 0;
  7. repeat
  8. Temp[I] := Chr((Val mod 10) + Ord('0'));
  9. Val := Val div 10;
  10. Inc(I);
  11. until (Val = 0) or (I = Width);
  12. // add spaces
  13. J := Width - I;
  14. FillChar(Dst^, J, PadChar);
  15. // add sign
  16. if NegSign then
  17. begin
  18. if PadChar = '0' then
  19. begin
  20. Dst[0] := '-';
  21. end else begin
  22. if J = 0 then
  23. begin
  24. // need one character for sign, shorten
  25. Inc(J);
  26. Dec(I);
  27. end;
  28. Dst[J - 1] := '-';
  29. end;
  30. end;
  31. // copy value, stored backwards
  32. repeat
  33. Dec(I);
  34. Dst[J] := Temp[I];
  35. Inc(J);
  36. until I = 0;
  37. // done!