# C# calculation errors

I have a c# code which calculates (304/1000)*100, which equals 30.4, however when I run the code in c# every single time I get 0.

```
decimal width = (maxSize.Width/ maxValue) * value; //304, 1000, 100 respectively
Console.WriteLine(width); //Returns 0
```

I don't understand what the hell is going on?

Aron
commented

Possible duplicate of C# Maths gives wrong results!

### 2 Answers

Your input variables are all of type int. Cast any of them into decimal or suffix the number with the letter M to convert to a decimal before the calculation is performed.

Pranav Negandhi
posted this

Use correct type

```
maxSize.Width = 304m;
maxValue = 1000m;
value=100m;
decimal width = (maxSize.Width/ maxValue) * value;
```

burning_LEGION
posted this

## Have an answer?

JD

Hint: what is the smallest integer that can represent 304/1000?