There is no direct way to round a double value with a zero value. You need to check if the variable has a value: if so, round it; otherwise return null.
You need to drop a little if you do this with a conditional statement ?::
double? result = myNullableDouble.HasValue
? (double?)Math.Round(myNullableDouble.Value)
: null;
As an alternative:
double? result = null;
if (myNullableDouble.HasValue)
{
result = Math.Round(myNullableDouble.Value);
}
source
share