[fpc-pascal] Formatting Question

Travis Siegel tsiegel at softcon.com
Sat Apr 3 18:27:51 CEST 2021


You can always convert the number to a string, then format it 
accordingly.  It's probably not the solution you want, but it will do 
the trick.

On 4/3/2021 11:43 AM, James Richters via fpc-pascal wrote:
> I'm looking for a way to format numerical data in a string so that everything ends up aligned by the decimal point.
> I've been trying to use the Format() function but I don't see how to do what I am looking for...
> then again I don't really understand the format() function, and most of the examples show exponents, which I do not want.
>
> My input variables are all Doubles and I want the result to be padded with spaces before the decimal point if needed and
> 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.
> 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.
>
> 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?
>
> James
>
>
> _______________________________________________
> fpc-pascal maillist  -  fpc-pascal at lists.freepascal.org
> https://lists.freepascal.org/cgi-bin/mailman/listinfo/fpc-pascal


More information about the fpc-pascal mailing list