我怎么能转换成十进制?为十进制

我怎么能转换成十进制?为十进制

问题描述:

可能是它是一个简单的问题,但我尝试所有转换方法!它仍然有错误! 你会帮我吗?

may be it is a simple question but I'm try all of conversion method! and it still has error! would you help me?

十进制? (可空十进制)以十进制

decimal? (nullable decimal) to decimal

有很多的选择......

There's plenty of options...

decimal? x = ...

decimal a = (decimal)x; // works; throws if x was null
decimal b = x ?? 123M; // works; defaults to 123M if x was null
decimal c = x.Value; // works; throws if x was null
decimal d = x.GetValueOrDefault(); // works; defaults to 0M if x was null
decimal e = x.GetValueOrDefault(123M); // works; defaults to 123M if x was null
object o = x; // this is not the ideal usage!
decimal f = (decimal)o; // works; throws if x was null; boxes otherwise