Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Round off a number after a calculation.

Posted on 2012-03-16
2
Medium Priority
?
370 Views
Last Modified: 2012-03-16
Hi,

I am programming in VS2010 with C#.
I have this code:

            if (e.Column.FieldName == "Value")
            {
                if ((Properties.Settings.Default.IsMGDL == false) && (CheckType(e.Value.ToString()) == false))
                {
                    int eValue = Convert.ToInt32(e.Value) / 18;
                    e.DisplayText = (eValue).ToString();
                }
                else if ((Properties.Settings.Default.IsMGDL == true) && (CheckType(e.Value.ToString()) == true))
                {
                    double eValue = Convert.ToDouble(e.Value) * 18;
                    e.DisplayText = (eValue).ToString();
                }
            }

Open in new window


In the first condition the calculated number has to round up in 1 decimal after the period.
or in my case the comma (f.e: 6,66666 has to be 6,7)

And in the second condition the calculated number as to round up as a whole number.
(f.e: 6,66666 has to be 7)

I hope I have explained it right!

How can I do that?

Peter
0
Comment
Question by:peterkiers
2 Comments
 
LVL 53

Accepted Solution

by:
Dhaest earned 2000 total points
ID: 37729304
Did you try the Math.Round

if (e.Column.FieldName == "Value")
            {
                if ((Properties.Settings.Default.IsMGDL == false) && (CheckType(e.Value.ToString()) == false))
                {
                    int eValue = Convert.ToInt32(e.Value) / 18;
                    e.DisplayText = (eValue).ToString();
                }
                else if ((Properties.Settings.Default.IsMGDL == true) && (CheckType(e.Value.ToString()) == true))
                {
                    double eValue = Math.Round(Convert.ToDouble(e.Value) * 18,1);
                    e.DisplayText = (eValue).ToString();
                }
            }
0
 
LVL 1

Author Comment

by:peterkiers
ID: 37729431
Thanks 500 p's comming to you...

Peter
0

Featured Post

Free learning courses: Active Directory Deep Dive

Get a firm grasp on your IT environment when you learn Active Directory best practices with Veeam! Watch all, or choose any amount, of this three-part webinar series to improve your skills. From the basics to virtualization and backup, we got you covered.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Welcome my friends to the second instalment and follow-up to our Minify and Concatenate Your Scripts and Stylesheets (http://www.experts-exchange.com/Programming/Languages/.NET/ASP.NET/A_4334-Minify-and-Concatenate-Your-Scripts-and-Stylesheets.html)…
In my previous article (http://www.experts-exchange.com/Programming/Languages/.NET/.NET_Framework_3.x/A_4362-Serialization-in-NET-1.html) we saw the basics of serialization and how types/objects can be serialized to Binary format. In this blog we wi…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…

963 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question