Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

cannot convert from 'double?' to 'decimal'

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?

like image 726
Criatura Eterna Avatar asked Mar 16 '23 14:03

Criatura Eterna


1 Answers

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.

like image 155
Yuval Itzchakov Avatar answered Mar 28 '23 15:03

Yuval Itzchakov