Forum > LazReport
[SOLVED] Format numbers and thousand separation in LazReport
artem101:
In my report template I display total sum with thousand separators.
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---Sum: [[field name] #N# ##0] rub.
It correctly shows 1234 as "1 234". But 12345678 looks like "12345 678". I need "12 345 678". How to fix? Thanks.
artem101:
Found solution:
--- Quote ---#N# ### ##0
--- End quote ---
dseligo:
It looks like LazReport calls FormatFloat from FP.
And FormatFloat probably doesn't handle space as thousand separator well.
If there is more digits in the number, your solution stops working.
So for 1234567890 you need to add more hashtags:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} ---ShowMessage(FormatFloat('### ### ### ##0', 1234567890));
:)
P.S.: And that solution adds spaces from left side if number is smaller.
wp:
--- Quote from: dseligo on October 30, 2025, 02:31:52 pm ---So for 1234567890 you need to add more hashtags:
P.S.: And that solution adds spaces from left side if number is smaller.
--- End quote ---
FormatFloat is meant to have the ThousandSeparator symbol (',') in the format mask: When this symbol is found the integer digits are grouped by three and separated by the Decimalseparator of the FormatSettings:
--- Code: Pascal [+][-]window.onload = function(){var x1 = document.getElementById("main_content_section"); if (x1) { var x = document.getElementsByClassName("geshi");for (var i = 0; i < x.length; i++) { x[i].style.maxHeight='none'; x[i].style.height = Math.min(x[i].clientHeight+15,306)+'px'; x[i].style.resize = "vertical";}};} --- FormatFloat('#,##0', 1234567890) ---> '1,234,567,890' (when FormatSettings.ThousandSeparator = ',') FormatFloat('#,##0', 1234567890) ---> '1 234 567 890' (when FormatSettings.ThousandSeparator = ' ') FormatFloat('#,##0.0', 1234567890.123) ---> '1.234.567.890,1' (when FormatSettings.ThousandSeparator = '.' and .Decimalseparator = ',')There is no need to have several '#' symbols, in fact FormatFloat(',#', 1234567890) has the same output as the first example above, and FormatFloat(',.0', 1234567890.123) as the last example.
But I am not sure whether this has any relevance to the OP's issue. I do not understand that 'N' inside the format string.
artem101:
--- Quote from: wp on October 30, 2025, 06:06:23 pm --- I do not understand that 'N' inside the format string.
--- End quote ---
Possible mistake. I copy-pasted this from somewhere.
Navigation
[0] Message Index
[#] Next page