1. Computing
Glossary|Tips/Tricks|FREE App/VCL|Books|Link Back

Delphi Programming RTL Reference|By Category|Alphabetically|By Unit

TFloatFormat type

unit
SysUtils
category
Floating point conversion routines
declaration
type TFloatFormat = (ffGeneral, ffExponent, ffFixed, ffNumber, ffCurrency);
description
An enumerated list of formatting codes for float functions.
  • ffGeneral - General number format.
    The value is converted to the shortest possible decimal string using fixed (ffFixed) or scientific (ffExponent) format. Trailing zeros are removed from the resulting string, and a decimal point appears only if necessary. The resulting string uses fixed point format if the number of digits to the left of the decimal point in the value is less than or equal to the specified precision, and if the value is greater than or equal to 0.00001. Otherwise the resulting string uses scientific format, and the Digits parameter specifies the minimum number of digits in the exponent (between 0 and 4).
  • ffExponent - Scientific format.
    The value is converted to a string of the form "-d.ddd...E+dddd". The resulting string starts with a minus sign if the number is negative, and one digit always precedes the decimal point. The total number of digits before the exponent in the resulting string (including the one before the decimal point) is given by the Precision parameter. The "E" exponent character in the resulting string is always followed by a plus or minus sign and up to four digits. The Digits parameter specifies the minimum number of digits in the exponent (between 0 and 4).
  • ffFixed - Fixed point format.
    The value is converted to a string of the form "-ddd.ddd...". The resulting string starts with a minus sign if the number is negative, and at least one digit always precedes the decimal point. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18. If the number of digits to the left of the decimal point is greater than the specified precision, the resulting value will use scientific format. ffNumber Number format. The value is converted to a string of the form "-d,ddd,ddd.ddd...". The ffNumber format corresponds to the ffFixed format, except that the resulting string contains thousand separators.
  • ffCurrency - Currency format.
    The value is converted to a string that represents a currency amount. The conversion is controlled by the CurrencyString, CurrencyFormat, NegCurrFormat, ThousandSeparator, and DecimalSeparator global variables, all of which are initialized from the Currency Format in the International section of the Windows Control Panel. The number of digits after the decimal point is given by the Digits parameter--it must be between 0 and 18.
example
var PI1000 : extended;

PI1000 := PI * 1000; // 3141592.6535897932385

FloatToStrF(pi1000,ffGeneral,12,2); 
// '3141.59265359'

FloatToStrF(pi1000,ffExponent,12,2);
// '3.14159265359E+03'

FloatToStrF(pi1000,ffFixed,12,2);
// '3141.59'

FloatToStrF(pi1000,ffNumber,12,2);
// '3,141.59'

FloatToStrF(pi1000,ffCurrency,12,2);
// '3,141.59 kn' (kn is currency symbol in Croatia)
in real code
see also
FloatToStrF,


Free Delphi code snippet inside every Delphi Newsletter!
Subscribe to the Newsletter
Name
Email

Got some code to share? Got a question? Need some help?
See More About

©2014 About.com. All rights reserved.