Page 1 of 1

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.
For example “MacOS X – Your question“, or “MS Word – Your Tip or Trick“.

Please note that switching to another language when reading a post will not bring you to the same post, in Dutch, as there is most likely no translated for the post!

Clear all

Lazarus - Format Integer or Int64 with thousands separator  


Noble Member Admin
Joined: 7 years ago
Posts: 1363
March 25, 2019 6:44 AM  

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.