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

Calculate percent from custom int

I’m pretty bad at maths and I’m hoping someone can help me with this or explain how it works. I am trying to program a custom progressbar where the location should just change where location x = 1 //0% and location x= 363 //100%. y is always 0

Here is the method I am trying to implement

private void SetProgressValue(int value)
        {
            // value min = 0;
            // value max = 100;

            //Location 1, 0 = 0%
            //Location 363, 0 = 100%

            Point newLocation;
            int result = value * 100 / 363;
            newLocation = new Point(result, 0);
            spanProgress.Location = new Point(newLocation.X, newLocation.Y);
        }

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

>Solution :

You problem is probably that you use ints to calculate fractions.

Suggestion:

float result = (value / 100.0) * 363;
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