Posted in C# Programming, Programming

Rounding up/down in C#

Random C# Notes. Using Visual Studio 2010. Some of this information has obtained through self-discovery, books, or random Google searches from other sites. I will give credit to the original author where due.

These are just plain code notes- not meant to be a tutorial.

Code is in italics.

Round  up/down a number or variable:

Math.Round(number, x);

Rounds a number “number” by “x” amount of places.

Math.Round(37.777, 2); //will result in 37.78


Create and activate a “Reset” or “Clear” button. This is useful if you want to clear the user’s entry. This code needs to be added after double-clicking the button which will “clear” or “reset” the field.

TextBox.Clear(); //(WPF)
TextBox.ResetText(); //(Windows Form Application)
label2.Text = ” “; // This sets the code for the label as one blank space, making it look empty (it’s not really empty, its value is a blank space… but it works, WPF)

Code for an “Exit” application button or command:


I’ve got to find a better way to do this… Maybe a OneNote document…

I’ll be back with more.