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
Step 1 − Divide the decimal number to be converted by the value of the new base. Step 2 − Get the remainder from Step 1 as the rightmost digit (least significant digit) of new base number. Step 3 − Divide the quotient of the previous divide by the new base.
An easy method of converting decimal to binary number equivalents is to write down the decimal number and to continually divide-by-2 (two) to give a result and a remainder of either a “1” or a “0” until the final result equals zero. So for example. Convert the decimal number 29410 into its binary number equivalent.
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
Try using the ??
operator:
decimal? value=12; decimal value2=value??0;
0 is the value you want when the decimal?
is null.
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With