I am reading an XML file and I am parsing the information. I am trying to convert the double to an int like this
var pruebaPago = Math.Ceiling(row[i].Pagado);
but when I run my code I get the following error:
cannot convert from 'double?' to 'decimal'
The XML file has the following definition for Pagado
<s:element name="Pagado" type="s:double" nillable="true"/>
How can I covert the nillable value and round it the nearest integer?
You'll want to use Nullable<double>.Value
. You'll also want to check that the value isn't null
first:
if (row[i].Pagado.HasValue)
{
var pruebaPago = Math.Ceiling(row[i].Pagado.Value);
}
The current overload resolution finds the decimal
overload the best match for Math.Ceiling
, as you pass a double?
and not a double
.
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