[fpc-pascal] Formatting Question
Jean SUZINEAU
jean.suzineau at wanadoo.fr
Sun Apr 4 09:02:38 CEST 2021
Le 04/04/2021 à 02:41, James Richters a écrit :
> That looks almost perfect.. can I suppress the trailing zeros with the
> format command without losing the alignment?
As far as I know, no ...
Not with just the RTL.
Anyway I have personal code for this, you can extract and customize it
to yours needs, it's released under LGPL :
program Format_Example;
uses
sysutils,uReal_Formatter,uuStrings;
procedure FF( _d: double);
var
S: String;
begin
S:= Fixe_MinE( Format_Float(_d, True, 3), 7);
WriteLn( S);
end;
begin
FF(0.5);
FF(2.53);
FF(12.5);
end.
------- Output -----
0.5
2.53
12.5
You can find the used units there:
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uReal_Formatter.pas
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/uuStrings.pas
(just extract functions Fixe_MinE / Fixe_Min0 or you will have to use a
bunch of other units from the same directory
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/)
https://github.com/jsuzineau/pascal_o_r_mapping/blob/TjsDataContexte/pascal_o_r_mapping/02_Units/u_sys_.pas
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.freepascal.org/pipermail/fpc-pascal/attachments/20210404/4e48ba93/attachment.htm>
More information about the fpc-pascal
mailing list