<p style="padding:0 0 0 0; margin:0 0 0 0;">Hi,</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">I tried this (add StrUtils to uses):</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">procedure TForm1.Button1Click(Sender: TObject);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">var i, l: Integer;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aV: Double;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aF: TFormatSettings;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aF.DecimalSeparator:='.';</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aF.ThousandSeparator:=' ';</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> for i:=-2 to 10 do</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> begin</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> aV:=pi*power(10, i);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> l:=length(intToStr(trunc(aV)));</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> l:=15-l-((l-1) div 3);</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> writeln(AddChar(' ', '', l)+FormatFloat('#,##0.######', aV, aF));</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> end;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">end;</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">Tweak it to your needs, it aligns well to console (up to 999 999 999 999.xxxxx) here.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;"> </p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">V.</p>
<p style="padding:0 0 0 0; margin:0 0 0 0;">______________________________________________________________<br />
> Od: "James Richters via fpc-pascal" <fpc-pascal@lists.freepascal.org><br />
> Komu: "'FPC-Pascal users discussions'" <fpc-pascal@lists.freepascal.org><br />
> Datum: 03.04.2021 17:53<br />
> Předmět: [fpc-pascal] Formatting Question<br />
></p>
I'm looking for a way to format numerical data in a string so that everything ends up aligned by the decimal point. <br />
I've been trying to use the Format() function but I don't see how to do what I am looking for... <br />
then again I don't really understand the format() function, and most of the examples show exponents, which I do not want.<br />
<br />
My input variables are all Doubles and I want the result to be padded with spaces before the decimal point if needed and <br />
trailing zeros to be replaced with spaces so that it always is the same total width and the decimal point is always in the same position.<br />
The string will later be either output to the console or saved into a file. It will only ever be viewed with a fixed width font.<br />
<br />
Does anyone have any idea if this can be done with any function included with FPC or am I going to write my own function to do this?<br />
<br />
James<br />
<br />
<br />
_______________________________________________<br />
fpc-pascal maillist - fpc-pascal@lists.freepascal.org<br />
<a href="https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal">https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal</a><br />