一、c#中decimal ,double,float的区别
浮点型
Name(类型) |
CTS Type |
Description(比特数) |
Significant Figures(有效数字) |
Range (approximate)(数值范围) |
---|---|---|---|---|
float |
System.Single |
32-bit single-precision floating point |
7 |
±1.5 × 10?45 to ±3.4 × 1038 |
double |
System.Double |
64-bit double-precision floating point |
15/16 |
±5.0 × 10 ?324 to ±1.7 × 10308 |
如果我们在代码中写一个12.3,编译器会自动认为这个数是个double型。所以如果我们想指定12.3为float类型,那么你必须在数字后面加上F/f:
float f = 12.3F;
decimal类型
作为补充,decimal类型用来表示高精度的浮点数