Docs-.NET-C # - Guide - Language Reference - keyword - value types: - type floating-point value

ylbtech-Docs-.NET-C # - Guide - Language Reference - keyword - value types: - type floating-point value

 

1. Back to top
1、

Floating point value type (C # reference)

"Floating point type" is "simple type" subset, you can use the text to initialize. All floating-point type is a value type. All types are supported floating-point number arithmetic , comparison , and equal operators .

Floating-point types of features

C # supports the following predefined floating-point type:

Type C # / Keyword Approximate range accuracy size .NET type
float ± 1.5 x 10-45 to ± 3.4 x 1038 About 6-9 digits 4 bytes System.Single
double ± 5.0 × 10-324 to ± 1.7 × 10308 About 15-17 digits 8 bytes System.Double
decimal ± 1.0 x 10-28 to ± 7.9228 x 1028 28-29 place 16 bytes System.Decimal

In the above table, the left most column of each type C # keywords are .NET type corresponding alias. They are interchangeable. For example, the following statement declares the same types of variables:

C#
double a = 12.3;
System.Double b = 12.3;

The default value for each floating-point type are zero 0Each has a float type  MinValue and  MaxValue constants, providing a limited minimum and maximum value for that type. float and  double type also offers may represent a non-numeric constants and infinite value. For example, double the type of the following constants: Double.NaN , Double.NegativeInfinity  and  Double.PositiveInfinity .

With  float and  double compared to decimal the type having a higher accuracy and a smaller range , it is suitable for financial and currency .

It can be mixed in expressions integer type and floating-point types. In this case, the integer type are converted to floating point type. The expression is evaluated according to the following rules:

  • If a floating-point type is  doublethe type of expression evaluation and comparison in relation Comparison equal  double or  BOOL .
  • If the expression is not  double the type of the expression is evaluated in relation to the type and equal comparison Comparison  float or  BOOL .

Floating-point expression can contain the following sets of values:

  • Positive and negative zero
  • Positive and negative infinity
  • Non-numeric value (NaN)
  • A limited set of non-zero value

For more information about these values, refer to  the IEEE  the IEEE standard binary floating-point arithmetic website provides.

You can use standard digital format string or a custom format string digital floating-point values format.

Authentic text

A true copy of the type determined by the suffix, as follows:

  • With or without text suffix  d or  D type text suffixed double
  • With  f or  F type text suffixed float
  • With  m or  M type text suffixed decimal

The following code shows examples of each type:

C#
double d = 3D;
d = 4d;
d = 3.934_001;

float f = 3_000.5F;
f = 5.4f;

decimal myMoney = 3_000.5m;
myMoney = 400.75M;

The previous example also demonstrates how to  _ as number separators (from start to support C # 7.0). Digital delimiter can be used for all types of digital text.

It may also be used scientific notation, which specifies the real part of the index of the text, as shown in the following example:

C#
double d = 0.42e2;
Console.WriteLine(d);  // output 42;

float f = 134.45E-2f;
Console.WriteLine(f);  // output: 1.3445

decimal m = 1.5E6m;
Console.WriteLine(m);  // output: 1500000

 

Change

Only one type of floating-point values between implicit conversion: from  float to  doubleHowever, you can use explicit casts to convert any floating point to any other type of floating type. For more information, please refer to the built-in numeric conversion .

C # Language Specification

For more information, see the  C # language specification the following sections:

See

2、
2. Return to top
 
3. Back to top
 
4. Top
 
5. Top
1、
2、
 
6. Back to top
 
warn Author: ylbtech
Source: http://ylbtech.cnblogs.com/
This article belongs to the author and blog Park total, welcome to reprint, but without the author's consent declared by this section must be retained, and given the original connection in the apparent position of the article page, otherwise reserves the right to pursue legal responsibilities.

Guess you like

Origin www.cnblogs.com/storebook/p/11846173.html