Page 1 of 1

Lazarus – Format Integer or Int64 with thousands separator

Lazarus – Format Integer or Int64 with thousands separator

Welcome to the Tweaking4All community forums!
When participating, please keep the Forum Rules in mind!

Topics for particular software or systems: Start your topic link with the name of the application or system.
Examples: "MacOS X - Your question", "MS Word - Your Tip or Trick".

Please note that switching to another language when reading a post will not work!
Posts will not have a translated counterpart.

RSS Feed

Home Forums Software Development Delphi, Lazarus, Free Pascal Lazarus – Format Integer or Int64 with thousands separator

This topic contains 0 replies, has 1 voice, and was last updated by  hans 4 months, 3 weeks ago.

Viewing 1 post (of 1 total)
  • Author
  • 11792


    This took me a few seconds to figure out, so as usual I post my “solution” here.

    What is the situation?
    I have a file size (using the FileUtils.FileSize(‘filename’) function in bytes (Int64).
    However I’d like to display that with the thousands separator, so for example 1234567890 becomes 1,234,567,890.

    the default functions didn’t like the fact that I passed it an Integer (why would this even be a problem?) and the documentation of the Format function (here and here) are kind-a crappy … (I can’t complain, since I’m not updating the Wiki page either)

    Anyhoo, the fix:

      Label1.Caption := Format('%.0N',[FileSizeInBytes+0.1-01]);

    To make the Integer (int64) a float, I add 0.1 and next subtract 0.1. To format the new “float” without numbers behind the decimal point (.0) and have it use thousands separators (N), use the “%.0N” format placeholder.

Viewing 1 post (of 1 total)

You must be logged in to reply to this topic.