• FormatFloat


    http://www.delphibasics.co.uk/RTL.asp?Name=FormatFloat

    1  function FormatFloat ( const Formatting : string; Value : Extended ) : string;
    2  function FormatFloat ( const Formatting : string; Value : Extended; FormatSettings : TFormatSettings ) : string;
     
    Description
    The FormatFloat function provides rich Formatting of a floating point number Value into a string. 
     
    The Formatting string may contain a mix of freeform text and control characters: 
     
      : Forces digit display or 0
    : Optional digit display
    : Forces display of thousands
    : Forces display of decimals
    E+  : Forces signed exponent display
    E-  : Optional sign exponent display
    : Separator of +ve and -ve and zero values

     
    These are best understood by looking at the sample code. 
     
    Version 2 of this function is for use within threads. You furnish the FormatSettings record before invoking the call. It takes a local copy of global formatting variables that make the routine thread safe.
     
    Related commands
    CurrencyDecimals   Defines decimal digit count in the Format function
    CurrencyFormat   Defines currency string placement in curr display functions
    CurrencyString   The currency string used in currency display functions
    DecimalSeparator   The character used to display the decimal point
    FloatToStrF   Convert a floating point value to a string with formatting
    Format   Rich formatting of numbers and text into a string
    FormatCurr   Rich formatting of a currency value into a string
    FormatDateTime   Rich formatting of a TDateTime variable into a string
    NegCurrFormat   Defines negative amount formatting in currency displays
    StrToFloat   Convert a number string into a floating point value
    ThousandSeparator   The character used to display the thousands separator
     Download this web site as a Windows program.
     
    Example code : Showing all of the formatting data types
    var
      float : extended;

    begin
      // Set up our floating point number
      float := 1234.567;

      // Display a sample value using all of the format options

      // Round out the decimal value
      ShowMessage('##### : '+FormatFloat('#####', float));
      ShowMessage('00000 : '+FormatFloat('00000', float));
      ShowMessage('0     : '+FormatFloat('0'    , float));
      ShowMessage('#,##0 : '+FormatFloat('#,##0', float));
      ShowMessage(',0    : '+FormatFloat(',0'   , float));
      ShowMessage('');

      // Include the decimal value
      ShowMessage('0.#### : '+FormatFloat('0.####', float));
      ShowMessage('0.0000 : '+FormatFloat('0.0000', float));
      ShowMessage('');

      // Scientific format
      ShowMessage('0.0000000E+00 : '+FormatFloat('0.0000000E+00', float));
      ShowMessage('0.0000000E-00 : '+FormatFloat('0.0000000E-00', float));
      ShowMessage('#.#######E-## : '+FormatFloat('#.#######E-##', float));
      ShowMessage('');

      // Include freeform text
      ShowMessage('"Value = "0.0 : '+FormatFloat('"Value = "0.0', float));
      ShowMessage('');

      // Different formatting for negative numbers
      ShowMessage('0.0 : '+FormatFloat('0.0'              , -1234.567));
      ShowMessage('0.0 "CR";0.0 "DB" : '+
                  FormatFloat('0.0 "CR";0.0 "DB"', -1234.567));
      ShowMessage('0.0 "CR";0.0 "DB" : '+
                  FormatFloat('0.0 "CR";0.0 "DB"',  1234.567));
      ShowMessage('');

      // Different format for zero value
      ShowMessage('0.0 : '+FormatFloat('0.0' , 0.0));
      ShowMessage('0.0;-0.0;"Nothing" : '+
                  FormatFloat('0.0;-0.0;"Nothing"', 0.0));
    end;
    Show full unit code
       ##### : 1235
       00000 : 01235
       0     : 1235
       #,##0 : 1,235
       ,0    : 1,235
       
       0.#### : 1234.567
       0.0000 : 1234.5670
       
       0.0000000E+00 : 1.2345670E+03
       0.0000000E-00 : 1.2345670E03
       #.#######E-## : 1.234567E3
       
       "Value = " : Value = 1234.6
       
       0.0 : -1234.6
       0.0 "CR";0.0 "DB" : 1234.6 DB
       0.0 "CR";0.0 "DB" : 1234.6 CR
       
       0.0 : 0.0
       0.0;-0.0;"Nothing" : Nothing
     
  • 相关阅读:
    1113.层级 Walker
    118.防止高度塌陷 Walker
    1114.实战移入切换 Walker
    116.清除浮动 Walker
    Vue使用——vue设置浏览器显示图标
    MFC如何高效地绘图(转)
    Ugly Windows HDU2487 ACM算法设计
    CImage类的介绍与使用 【图像打开,另存为,转为灰度图像(利用cimage方法实现)】
    Ogre 3D 配置
    WPF文本框只允许输入数字[转]
  • 原文地址:https://www.cnblogs.com/findumars/p/3496103.html
Copyright © 2020-2023  润新知