# Rounding decimal to whole number.

Page 1 of 1

## 4 Replies - 385 Views - Last Post: 02 September 2012 - 09:15 PMRate Topic: //<![CDATA[ rating = new ipb.rating( 'topic_rate_', { url: 'http://www.dreamincode.net/forums/index.php?app=forums&module=ajax&section=topics&do=rateTopic&t=290773&amp;s=139e4c16e8ac2ba5f54a132961b7dd07&md5check=' + ipb.vars['secure_hash'], cur_rating: 0, rated: 0, allow_rate: 0, multi_rate: 1, show_rate_text: true } ); //]]>

### #1 ecarter202

• New D.I.C Head

Reputation: -1
• Posts: 8
• Joined: 02-September 12

# Rounding decimal to whole number.

Posted 02 September 2012 - 09:05 PM

This program works, just rounding the decimal to a whole number. I've tried String.Format & Math.Round. Didn't work however I did it. ha. Please Help!!

```using System;

class Program
{
static void Main()
{
int w; // Radius of Circle
int x; // Side of the Square * 2
int y; // Area of the Square
decimal z; // Radius squared

Console.WriteLine("Enter the circle's radius: ");

x = w * 2;
y = x * x;
z = w * w * 3.14m;
z = Math.Round(z, 2);

Console.WriteLine("The shaded area is: " + (y - z));

}

}
```

Is This A Good Question/Topic? 0

## Replies To: Rounding decimal to whole number.

### #2 Mina-no-Hime

Reputation: 98
• Posts: 176
• Joined: 23-August 12

## Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:07 PM

"It didn't work" doesn't tell us what happened.

What input did you give, what results did you get, and what results did you expect?

### #3 ecarter202

• New D.I.C Head

Reputation: -1
• Posts: 8
• Joined: 02-September 12

## Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:09 PM

Sorry. Just figured you'd attempt it yourself. I put in 10 and it should print 85.8 something. But it prints out 86.00.

### #4 Mina-no-Hime

Reputation: 98
• Posts: 176
• Joined: 23-August 12

## Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:12 PM

1) Never assume we're going to do your work for you.

2) Look at your math. If you input 10, you're doing:
```w = 10
x = w * 2 = 10 * 2 = 20
y = x * x = 20 * 20 = 400
z = w * w * 3.14 = 10 * 10 * 3.14 = 100 * 3.14 = 314
z = Round(z, 2) = Round(314, 2) = 314
```

Then you're printing
```y - z = 400 - 314 = 86
```

This post has been edited by Mina-no-Hime: 02 September 2012 - 09:13 PM

### #5 ecarter202

• New D.I.C Head

Reputation: -1
• Posts: 8
• Joined: 02-September 12

## Re: Rounding decimal to whole number.

Posted 02 September 2012 - 09:15 PM

okay. i feel like a damn retard; but happy that it actually works.

thank you for letting me waste some of your time this evening.
and sorry.