C#中的Decimal.ToSingle()方法
C#中的Decimal.ToSingle()方法用于将指定的Decimal的值转换为等效的单精度浮点数。
语法
以下是语法-
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
热门推荐
10 城堡文案简短婚礼祝福语
11 参加儿子大学祝福语简短
12 朋友家住豪宅祝福语简短
13 最美婆婆生日祝福语简短
14 家长祝福语大全简短内容
15 男生打球祝福语简短霸气
16 朋友花篮开业祝福语简短
17 三八简短祝福语给婆婆
18 夸赞老师祝福语搞笑简短