I need to round the sum of decimal?. I do:
group => new {
rounded_sum = group.Sum(f => f.A) == null ? null : (decimal?)Decimal.Round((decimal)group.Sum(f => f.A), 0),
}
which isn’t very nice. Perhaps there is a cleaner way?
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
Could you use the null coalescing operator? I realize that it doesn’t do exactly the same thing, but it might be appropriate.
Another alternative would be to do the operation in two steps, which would save running the sum operation twice, though it’s even “wordier.”