Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

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.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 6231293
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 24, 20262026-05-24T09:54:34+00:00 2026-05-24T09:54:34+00:00

I am running a LINQ query that is using local let variables to calculate

  • 0

I am running a LINQ query that is using local “let” variables to calculate a local value to compare against a parameter that is passed into the query.

I have the following query:

Items = from lead in Items
        let total = lead.NurtureActions.Count(q => !q.Deleted)
        let completed = lead.NurtureActions.Count(nurtureAction => nurtureAction.Completed && !nurtureAction.Deleted)
        let percentage = Math.Round((Double)((completed/total)*100),0,MidpointRounding.ToEven)
        where 
            total>0 && 
            percentage == progress
        select lead;

The part that is really important above is the following line:

let percentage = Math.Round((Double)((completed/total)*100),0,MidpointRounding.ToEven)

As you can see in my query, I am comparing the result of that query with progress, which is passed into my function.

For example: I might pass in the value 8, so progress will have the value 8. But the calculated percentage might initially be 8.223, but I need that to round to 8.

I believed that I was doing this correctly, but for some reason, something is not working correctly.

Any ideas of what might be throwing the rounding off? I have also tried the AwayFromZero option for rounding, but that doesn’t work either.

Edit For those who requested more information, I am not sure what value it is calculating. I am not experienced with debugging LINQ queries, and wouldn’t know where to begin to find out what that value is. I would provide it if I knew how to get it.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-24T09:54:36+00:00Added an answer on May 24, 2026 at 9:54 am

    Random guess: total and completed are ints, so (completed/total) results in a truncated value. The truncated value is multiplied by 100 and then converted to double.

    I guess this produces unexpected results in some cases if you expect that (completed/total) returns a double.

    Fix:

    let total = (double)lead.NurtureActions.Count(...)
    let completed = (double)lead.NurtureActions.Count(...)
    let percentage = Math.Round((completed/total)*100, ...)
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

So I'm trying to do a simple insert using Linq but i'm running into
I am running a query using Linq2SQL that comes down to following query: DateTime?
I'm running a linq-to-sql query on a table that contains a nullable datetime like
I've a semi complex LINQ query that is running very slow. I do not
I'm having some problems running a LINQ query off of a LINQ2SQL class that
I'm running into an issue calling a User Defined Function from a LINQ query.
I'm constantly running up against this when writing queries with LINQ-to-XML: the Value property
I'm trying to do a JOIN in Linq using lambda expressions ... and running
I am trying to get some XML data with LINQ, but running into a
Running into a problem where on certain servers we get an error that the

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.