C#-------浮点数据类型

c++数据类型大小受操作平台的影响,而在c#中,数据类型的定义都以与平台无关的方式定义,以备将来C#和.NET迁移到其他平台上。

这里说一下浮点类型在c#语言中的定义。

c#可以支持float ,double和decimal浮点数据类型。

 1 using System;
 2 using System.Collections.Generic;
 3 using System.Linq;
 4 using System.Text;
 5 using System.Threading.Tasks;
 6 
 7 namespace ConsoleApplication1
 8 {
 9     class Program
10     {
11         static void Main(string[] args)
12         {
13             Console.WriteLine("sizeof float={0},double={1},decimal={2}",sizeof(float),sizeof(double),sizeof(decimal));
14             Console.ReadKey();
15         }
16     }
17 }

运行结果:

sizeof float=4,double=8,decimal=16

 

posted on 2019-10-07 14:46  Milo_lu  阅读(3126)  评论(0编辑  收藏  举报

导航