Solved

Round off a number after a calculation.

Posted on 2012-03-16
2
360 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 500 total points
Comment Utility
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
Comment Utility
Thanks 500 p's comming to you...

Peter
0

Featured Post

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

A basic question.. “What is the Garbage Collector?” The usual answer given back: “Garbage collector is a background thread run by the CLR for freeing up the memory space used by the objects which are no longer used by the program.” I wondered …
A long time ago (May 2011), I have written an article showing you how to create a DLL using Visual Studio 2005 to be hosted in SQL Server 2005. That was valid at that time and it is still valid if you are still using these versions. You can still re…
Access reports are powerful and flexible. Learn how to create a query and then a grouped report using the wizard. Modify the report design after the wizard is done to make it look better. There will be another video to explain how to put the final p…
In this tutorial you'll learn about bandwidth monitoring with flows and packet sniffing with our network monitoring solution PRTG Network Monitor (https://www.paessler.com/prtg). If you're interested in additional methods for monitoring bandwidt…

772 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

Need Help in Real-Time?

Connect with top rated Experts

11 Experts available now in Live!

Get 1:1 Help Now