Util.FormatFloat

Top  Previous  Next

 

Syntax

function Util.FormatFloat(FormatStr: string; FloatValue: float): string

 

Alternative Names

ibec_FormatFloat

 

Description

Formats the given FloatValue according to the format as specified in FormatStr.

 

Returns a string with a formatted floating point value.

 

Specifier

Displays

0

Digit placeholder. Outputs a digit if there's a digit available in the value, or 0 otherwise.

#

Digit placeholder. Outputs a digit if there's a digit available in the value, or nothing otherwise.

.

Decimal point. The first '.' in the FormatStr is the location for the DecimalSeparator system text, additional '.' characters are ignored.

,

Thousand separator. Use 1 or more ',' characters in the FormatStr in order to output ThousandSeparator system text.

E+ or E-

Scientific notation. Use scientific notation for the value. You can use up to four 0-characters followed by E+/E- to determine the minimum number of digits for the exponent. Using E+ outputs both a plus and minus sign for the exponent, using E- outputs only a minus sign for the exponent. Not case sensitive.

'xx'/"xx"

Characters enclosed in single or double quotation marks are displayed as such, and do not affect formatting.

;

Separates multiple formatting strings for positive, negative and zero numbers.

 

The following table shows some sample formats and the results produced when the formats are applied to different values (Windows regional settings have '.' as the decimal separator and ',' as the thousand separator):

Format

1234

-1234

0.5

0

1234

-1234

1

0.00

1234.00

-1234.00

0.50

#,##

1234

-1234

1

#,##0.00

1,234.00

-1,234.00

0.50

#,##0.00;(#,##0.00)

1,234.00

(1,234.00)

0.50

 

The decimal separator and thousand separator are taken from the Control Panel and can be modified using Util.SetSystemText.

 

See Also

Util.SetSystemText

 

Example

execute UDSBlock

as

begin

  /* outputs 1234.00 */

  floatstr_alwaysdecimals = Util.FormatFloat('0.00', 1234);

  /* outputs 1234 */

  floatstr_nodecimals = Util.FormatFloat('#.##', 1234); 

  GUI.ShowMessage('With specified decimals: ' || floatstr_alwaysdecimals || String.CRLF() || 'Without specified decimals: ' || floatstr_nodecimals);

  

  /* outputs 1234.05 */

  floatstr1 = Util.FormatFloat('0.00', 1234.05);

  /* outputs 1234.05 */

  floatstr2 = Util.FormatFloat('#.##', 1234.05);

  GUI.ShowMessage('With specified decimals: ' || floatstr1 || String.CRLF() || 'Without specified decimals: ' || floatstr2);

  

  /* outputs -1234.05 */

  floatstr1 = Util.FormatFloat('0.00', -1234.05);

  /* outputs (1234.05) */

  floatstr2 = Util.FormatFloat('0.00;(0.00)', -1234.05);

  GUI.ShowMessage('Positive & negative have some format: ' || floatstr1 || String.CRLF() || 'Negative specific format: ' || floatstr2);

 

  Util.SetSystemText(__sysDecimalSeparator, ',');

  floatstr1 = Util.FormatFloat('0.00', 1234.05);

  GUI.ShowMessage('Changed decimal separator: ' || floatstr1);

end