C 浮点常量C Floating-Point Constants

“浮点常量”是表示带符号实数的十进制数字。A "floating-point constant" is a decimal number that represents a signed real number. 带符号实数的表现形式包括整数部分、小数部分和指数。The representation of a signed real number includes an integer portion, a fractional portion, and an exponent. 浮点常量用于表示不可更改的浮点值。Use floating-point constants to represent floating-point values that cannot be changed.


   fractional-constant exponent-partopt floating-suffixopt   fractional-constant exponent-partopt floating-suffixopt
   digit-sequence exponent-part floating-suffixopt   digit-sequence exponent-part floating-suffixopt

   digit-sequenceopt .   digit-sequenceopt . digit-sequencedigit-sequence
   digit-sequence .   digit-sequence .

   e signopt digit-sequence   e signopt digit-sequence
   E signopt digit-sequence   E signopt digit-sequence

sign:一个 sign : one of
   + -   + -

   digit   digit
   digit-sequence digit   digit-sequence digit

floating-suffix一个 floating-suffix : one of
   f l F L   f l F L

你可以省略小数点前面的数字(整数部分)或小数点后面的数字(小数部分),但不能同时省略。You can omit either the digits before the decimal point (the integer portion of the value) or the digits after the decimal point (the fractional portion), but not both. 仅当包括一个指数时可省略小数点。You can leave out the decimal point only if you include an exponent. 空白字符不能分隔常量的数字或字符。No white-space characters can separate the digits or characters of the constant.

以下示例阐释了某些形式的浮点常量和表达式:The following examples illustrate some forms of floating-point constants and expressions:

1.575E1   /* = 15.75   */  
1575e-2   /* = 15.75   */  
-2.5e-3   /* = -0.0025 */  
25E-4     /* =  0.0025 */  

浮点常量为正数,除非它们的前面有减号 (-)。Floating-point constants are positive unless they are preceded by a minus sign (-). 在这种情况下,减号将视为一元算术求反运算符。In this case, the minus sign is treated as a unary arithmetic negation operator. 浮点常量包括类型 floatdoublelong doubleFloating-point constants have type float, double, or long double.

浮点常量没有 fFl,或者 L 后缀类型为 doubleA floating-point constant without an f, F, l, or L suffix has type double. 如果后缀是字母 fF,则该常量类型为 floatIf the letter f or F is the suffix, the constant has type float. 如果后缀是字母 lL,则该常量类型为 long doubleIf suffixed by the letter l or L, it has type long double. 例如: For example:

100L  /* Has type long double  */  
100F  /* Has type float        */  

请注意,与 double 类型相同,Microsoft C 编译器在内部表示 long doubleNote that the Microsoft C compiler internally represents long double the same as type double. 请参阅基本类型的存储,了解有关类型 doublefloatlong double 的信息。See Storage of Basic Types for information about type double, float, and long double.

如下例所示,可以省略浮点常量的整数部分。You can omit the integer portion of the floating-point constant, as shown in the following examples. 可以通过包括下列方式在内的多种方式表达 .75:The number .75 can be expressed in many ways, including the following:


另请参阅See Also

C 常量C Constants