From Clomosy Docs
function FormatFloat(const Format: string; Value: Double): string;
The FormatFloat function converts a numeric value (Double or Float) into a string according to the given Format string. The format string defines how the number will appear in the output. It can contain numeric formatting characters, optional placeholders, separators, scientific notation, percentages, and literal text.
| Format | Description |
|---|---|
| 0 Mandatory digit | Always shows a digit; if missing, filled with 0 |
| # Optional digit | Shows a digit if present; otherwise left blank |
| . Decimal separator | Marks the decimal point (system locale dependent) |
| , Thousands separator | Groups digits in thousands (system locale dependent) |
| E+00 / E-00 Scientific notation | Shows the number in exponential format |
| % Percent | Multiplies the number by 100 and adds a % sign |
| ; Positive/negative separator | Allows different formats for positive and negative numbers |
| 'text' Literal text | Displays the text exactly as written |
| \ Escape character | Displays the next character literally |
Example
var
myNumber: Double;
{
myNumber = 12345.6789;
// Mandatory integer
ShowMessage('0 = ' + FormatFloat('0', myNumber));
// Two decimal places
ShowMessage('0.00 = ' + FormatFloat('0.00', myNumber));
// Optional decimal places
ShowMessage('#.### = ' + FormatFloat('#.###', myNumber));
// Thousands separator for integer
ShowMessage('#,##0 = ' + FormatFloat('#,##0', myNumber));
// Thousands separator + 2 decimals
ShowMessage('#,##0.00 = ' + FormatFloat('#,##0.00', myNumber));
// Percent format
ShowMessage('0.00% = ' + FormatFloat('0.00%', myNumber/100));
// Scientific notation
ShowMessage('0.00E+00 = ' + FormatFloat('0.00E+00', myNumber));
// Negative number format
myNumber = -12345.6789;
ShowMessage('0;(#) = ' + FormatFloat('0;(#)', myNumber));
// Literal text
myNumber = 42.5;
ShowMessage('Value: 0.00 units = ' + FormatFloat('Value: 0.00 units', myNumber));
}
Output:
0 = 12346
0.00 = 12345.68
#.### = 12345.679
#,##0 = 12,346
#,##0.00 = 12,345.68
0.00% = 123.46%
0.00E+00 = 1.23E+04
0;(#) = (12346)
Value: 0.00 units = 42.50 units