【发布时间】:2017-08-26 13:50:58
【问题描述】:
如果十进制值大于浮点数(没有浮点数),我想抛出异常
下面的示例代码对整数工作正常(抛出溢出异常)
decimal a = decimal.MaxValue;
int b = checked(int.Parse(a.ToString()));
但是这个示例代码没有抛出任何异常
decimal a = decimal.MaxValue;
float b = checked(float.Parse(a.ToString())); // b is 7.92281625E+28
如何判断小数的值是否大于浮点数(没有浮点数)?
【问题讨论】:
-
小数的整数部分总是适合浮点数。
-
find out if value of decimal is bigger than float(without floating point)是什么意思?你想把小数点后的所有东西都扔掉,然后比较整数部分吗? -
float的最大值为3.402823E+38。小数的最大值为79228162514264337593543950335。decimal不能大于float。
标签: c#