Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people, just like you, are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
Solved

Round off a number after a calculation.

Posted on 2012-03-16
2
365 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
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 Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

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)…
For those of you who don't follow the news, or just happen to live under rocks, Microsoft Research released a beta SDK (http://www.microsoft.com/en-us/download/details.aspx?id=27876) for the Xbox 360 Kinect. If you don't know what a Kinect is (http:…
Email security requires an ever evolving service that stays up to date with counter-evolving threats. The Email Laundry perform Research and Development to ensure their email security service evolves faster than cyber criminals. We apply our Threat…
In an interesting question (https://www.experts-exchange.com/questions/29008360/) here at Experts Exchange, a member asked how to split a single image into multiple images. The primary usage for this is to place many photographs on a flatbed scanner…

856 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