Follow

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use
Contact

how to make float sum calculation?

am I doing the addition wrong? The result does not give the total number

public float GetGrandTotal(UtilizationDto issues)
        {
            var grandTotal = 0.0f;
            grandTotal += (float)issues.PercentCalculation;
            return grandTotal;
        }

>Solution :

MEDevel.com: Open-source for Healthcare and Education

Collecting and validating open-source software for healthcare, education, enterprise, development, medical imaging, medical records, and digital pathology.

Visit Medevel

Just declare your grandTotal variable in global and on each call it will not reset 0

public float grandTotal {get; set;} = 0.0f;
public float GetGrandTotal(UtilizationDto issues)
{
     grandTotal += (float)issues.PercentCalculation;
     return grandTotal;
}

public float Main(){
    GetGrandTotal(new UtilizationDto { PercentCalculation= 1.0f});
    GetGrandTotal(new UtilizationDto { PercentCalculation= 2.0f});
    return grandTotal;
}
Add a comment

Leave a Reply

Keep Up to Date with the Most Important News

By pressing the Subscribe button, you confirm that you have read and are agreeing to our Privacy Policy and Terms of Use

Discover more from Dev solutions

Subscribe now to keep reading and get access to the full archive.

Continue reading