[fpc-pascal] Formatting Question

James Richters james.richters at productionautomation.net
Sat Apr 3 17:43:52 CEST 2021


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




More information about the fpc-pascal mailing list