C# 中的 Decimal.ToUInt16() 方法
C# 中的 Decimal.ToUInt16() 方法用于将指定 Decimal 的值转换为等效的 16 位无符号整数。
语法
以下为语法 −
public static ushort ToUInt16 (decimal val);
上述中,val 是要转换的十进制数字。
示例
我们现在来看一个示例来实现 Decimal.ToUInt16() 方法 −
using System;
public class Demo {
public static void Main(){
Decimal val = 875.647m;
Console.WriteLine("Decimal value = "+val);
ushort res = Decimal.ToUInt16(val);
Console.WriteLine("16-bit unsigned integer = "+res);
}
}输出
将产生以下输出 −
Decimal value = 875.647 16-bit unsigned integer = 875
示例
我们现在来看另一个示例来实现 Decimal.ToUInt16() 方法 −
using System;
public class Demo {
public static void Main(){
Decimal val = 0.001m;
Console.WriteLine("Decimal value = "+val);
ushort res = Decimal.ToUInt16(val);
Console.WriteLine("16-bit unsigned integer = "+res);
}
}输出
将产生以下输出 −
Decimal value = 0.001 16-bit unsigned integer = 0
广告
数据结构
网络
关系型数据库管理系统
操作系统
Java
iOS
HTML
CSS
Android
Python
C 编程
C++
C#
MongoDB
MySQL
Javascript
PHP