C# 中的 Decimal.ToSingle() 方法
C# 中的 Decimal.ToSingle() 方法用于将指定的小数的值转换为等效的单精度浮点数。
语法
以下是语法 −
public static float ToSingle (decimal val);
上述 Val 是要转换的小数。
示例
现在,我们来看一个示例来实现 Decimal.ToSingle() 方法 −
using System;
public class Demo {
public static void Main(){
Decimal val = 0.00000007575833m;
Console.WriteLine("Decimal value = "+val);
float res = Decimal.ToSingle(val);
Console.WriteLine("Single-precision floating-point number = "+res);
}
}输出
这将产生以下输出 −
Decimal value = 0.00000007575833 Single-precision floating-point number = 7.575833E-08
示例
现在,我们来看另一个示例来实现 Decimal.ToSingle() 方法 −
using System;
public class Demo {
public static void Main(){
Decimal val = 8767576576m;
Console.WriteLine("Decimal value = "+val);
float res = Decimal.ToSingle(val);
Console.WriteLine("Single-precision floating-point number = "+res);
}
}输出
这将产生以下输出 −
Decimal value = 8767576576 Single-precision floating-point number = 8.767576E+09
广告
数据结构
网络
RDBMS
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP