digit roundoff
-
i have a float type of variable i.e float t1=200.36 and t2=300.62. now i want to roundoff these two variables to their nearest degit. I want to show the information like this: t1=200.36 roundoff=-0.36 total=200 t2=300.62 roundoff=+0.38 total=301
-
i have a float type of variable i.e float t1=200.36 and t2=300.62. now i want to roundoff these two variables to their nearest degit. I want to show the information like this: t1=200.36 roundoff=-0.36 total=200 t2=300.62 roundoff=+0.38 total=301
-
i have a float type of variable i.e float t1=200.36 and t2=300.62. now i want to roundoff these two variables to their nearest degit. I want to show the information like this: t1=200.36 roundoff=-0.36 total=200 t2=300.62 roundoff=+0.38 total=301
See this code to get the idea:
double t1 = 200.36;
double t2 = 300.62;
int t11 = (int)Math.Round(t1, 0);
int t21 = (int)Math.Round(t2, 0);
MessageBox.Show("t1=" + t1.ToString() + " roundoff=" + (t11 - t1).ToString("0.00") + " total=" + Math.Round(t1, 0).ToString());
MessageBox.Show("t2=" + t2.ToString() + " roundoff=" + (t21 - t2).ToString("0.00") + " total=" + Math.Round(t2, 0).ToString()); -
i have a float type of variable i.e float t1=200.36 and t2=300.62. now i want to roundoff these two variables to their nearest degit. I want to show the information like this: t1=200.36 roundoff=-0.36 total=200 t2=300.62 roundoff=+0.38 total=301
I want to add the following What is required when the number is half i.e. 200.5. Whether 200 or 201? By default
Math.Round
followsMidpointRounding.ToEven
enumeration value.double number = 200.5;
Console.WriteLine (Math.Round(number,0));
Console.WriteLine (Math.Round(number,0, MidpointRounding.AwayFromZero));
double number2 = 201.5;
Console.WriteLine (Math.Round(number2,0));
Console.WriteLine (Math.Round(number2,0, MidpointRounding.AwayFromZero));
//The output from the above code will be
//200
//201
//202
//202So, if the next higher number is required always, when the value is half way, then
MidpointRounding.AwayFromZero
is to be used. -
i have a float type of variable i.e float t1=200.36 and t2=300.62. now i want to roundoff these two variables to their nearest degit. I want to show the information like this: t1=200.36 roundoff=-0.36 total=200 t2=300.62 roundoff=+0.38 total=301