Not Yet Answered # How do I round off

mvmalderen 2,072 ddanbe 2,503 avirag 10 ddanbe 2,503 avirag 10 ddanbe 2,503 OK, so HostGator for some reason no longer allows gcc/g++ access unless you have a Designated Server account, which is a lot of money to spend just to compile my "Hello World" program. Thus I figured I'd compile at home, then upload. Program is your regular old bare-bones Hello World ...

0

For the first case:

If your salary is 1000.23 it has to be 1000.25:

We multiply 1000.23 by 20, round it off to the nearest integer and divide it back by 20 :) ...

Edit:: In the second case (if your salary is 1000.26 and it has to rounded off to 1000.30): the Math.round function should work fine here !

Hope this helps !

0

I hope this snippet does what you want :

```
using System;
namespace ConsoleApplication1
{
class Program
{
static void Main(string[] args)
{
double d1 = 1000.23;
double d2 = 1000.26;
Console.WriteLine("d1= {0:F}", roundNum(d1,2));
Console.WriteLine("d2= {0:F}", roundNum(d2,2));
Console.ReadKey();
}
public static double roundNum(double num, int place)
{
double d = num * Math.Pow(10, place - 1);
double floorValue = Math.Floor(d);
if ((d - floorValue) > .5)
{
return (floorValue + 1) / Math.Pow(10, place - 1);
}
else
{
return (floorValue + 0.5) / Math.Pow(10, place - 1);
}
}
}
}
```

This does not work if **place **is smaller than **1**, you have to test for it!

0

Hi !!!

I want to make window application In which I want to roundoff two numbers to nearest tens or hundreds or thousands....

After rounding off,then I want to find its sum \diff\mult\div...

On the form I have three textboxes i.e.one for entering the question,second for nearest roundoff(10,100,100) and another textbox for displaying final result.

For example-:

In first text box I enter 367*231

In the second I enter 100

Now in third textbox result should be 80000(i.e 400*200=80000 because nearest 100 of 367 is 400 and that of 231 is 200)

can anyone give me C# code for making this application...

0

This is code to round 231 to the nearest hundred :

```
int i = 231;
double d = i/100.0;
double r = Math.Round(d, 0);
int roundInt = (int)r * 100;
```

0

Thanks for the code.......

this I already knew......

problem is that how will the computer recognise the expression in textbox1 i.e 367*231 and evaluate to solve the value

0

If you want to get help, post this question again in a new thread because this is a whole other issue then just rounding off.:-O

We will see you there:)

This article has been dead for over six months. Start a new discussion instead.

Recommended Articles

Hi. I have a form with list box : lst_product, datagridview : grd_order and button: btn_addline. lst_product has a list of product ids selected from database (MS Acess 2013) , grd_order is by default empty except for 2 headers and btn_addline adds rows to grd_order.

btn_addline :

`Private Sub btn_addline_Click(ByVal ...`

I don’t want at this stage work on a big separate project as I've already got plenty ...