[Overview][Constants][Types][Classes][Procedures and functions][Variables][Index] |
Format a float according to a certain mask.
Source position: line 0
function FormatFloat( |
const Format: String; |
Value: Extended |
):String; |
const Format: String; |
Value: Extended; |
const FormatSettings: TFormatSettings |
):String; |
FormatFloat formats the floating-point value given by Value using the format specifications in Format. The format specifier can give format specifications for positive, negative or zero values (separated by a semicolon).
If the formatspecifier is empty or the value needs more than 18 digits to be correctly represented, the result is formatted with a call to FloatToStrF with the ffGeneral format option.
The following format specifiers are supported:
If an error occurs, an exception is raised.
|
Convert a float value to a string using a fixed format. |
Program Example89; { This program demonstrates the FormatFloat function } Uses sysutils; Const NrFormat=9; FormatStrings : Array[1..NrFormat] of string = ( '', '0', '0.00', '#.##', '#,##0.00', '#,##0.00;(#,##0.00)', '#,##0.00;;Zero', '0.000E+00', '#.###E-0'); NrValue = 5; FormatValues : Array[1..NrValue] of Double = (1234,-1234,0.5,0,-0.5); Width = 12; FWidth = 20; Var I,J : Integer; S : String; begin Write('Format':FWidth); For I:=1 to NrValue do Write(FormatValues[i]:Width:2); Writeln; For I:=1 to NrFormat do begin Write(FormatStrings[i]:FWidth); For J:=1 to NrValue do begin S:=FormatFloat(FormatStrings[I],FormatValues[j]); Write(S:Width); end; Writeln; end; End.
lazarus-ccr.sourceforge.net |