Detailed demonstration of 'FormatFloat' and its diverse formatting specifiers. This example showcases the use of digit placeholders ('0' and '#'), thousand separators (','), decimal control, scientific notation ('E+'), and conditional formatting (positive;negative;zero), illustrating how to produce precise and human-readable numeric representations for UI, logs, or data exports.
<?pas
var val := 1234.5678;
PrintLn('Value: ' + val.ToString);
// Basic Formatting
PrintLn('Fixed width (00000.00): ' + FormatFloat('00000.00', val));
PrintLn('Optional digits (#####.##): ' + FormatFloat('#####.##', val));
// Thousand Separators
PrintLn('Currency style (#,##0.00): ' + FormatFloat('#,##0.00', val));
// Conditional Sections
var pos := 42.0;
var neg := -42.0;
var zero := 0.0;
var fmt := 'Positive: #.##;Negative: (#.##);Zero: zero';
PrintLn('Conditional (Pos): ' + FormatFloat(fmt, pos));
PrintLn('Conditional (Neg): ' + FormatFloat(fmt, neg));
PrintLn('Conditional (Zero): ' + FormatFloat(fmt, zero));
// Scientific Notation
PrintLn('Scientific (0.00E+00): ' + FormatFloat('0.00E+00', val));
// OUTPUT
// Value: 1234.5678
// Fixed width (00000.00): 01234.57
// Optional digits (#####.##): 1234.57
// Currency style (#,##0.00): 1,234.57
// Conditional (Pos): Positive: 42
// Conditional (Neg): Negative: (42)
// Conditional (Zero): Zero: zero
// Scientific (0.00E+00): 1.23E+03
?>
Value: 1234.5678 Fixed width (00000.00): 01234.57 Optional digits (#####.##): 1234.57 Currency style (#,##0.00): 1,234.57 Conditional (Pos): Positive: 42 Conditional (Neg): Negative: (42) Conditional (Zero): Zero: zero Scientific (0.00E+00): 1.23E+03