# How can I get a double by dividing two integers?

## Problem

How can I get a double by dividing two integers?

## Solution #1

You’d want to roll the dice:

``````double num3 = (double)num1/(double)num2;
``````

Note that in C#, if any of the parameters are doubles, a double division is performed, resulting in a double. As a result, the following would also work:

``````double num3 = (double)num1/num2;
``````

Dot Net Perls

## Solution #2

You can cast to decimal to get more precision:

``````(decimal)100/863
//0.1158748551564310544611819235
``````

Or:

``````Decimal.Divide(100, 863)
//0.1158748551564310544611819235
``````

Doubles are represented with 64 bits, while decimal is represented with 128 bits.

``````(double)100/863
//0.11587485515643106
``````

Take a look at this essay by Jon Skeet on floats and doubles, as well as this one about decimals, for further information on the binary floating point representation and its precision.

## Solution #3

The integers are converted to doubles.

## Solution #4

Convert one of them to a double first. This form can be used in a variety of languages:

`````` real_result = (int_numerator + 0.0) / int_denominator
``````

## Solution #5

``````var firstNumber=5000,
secondeNumber=37;

var decimalResult = decimal.Divide(firstNumber,secondeNumber);

Console.WriteLine(decimalResult );
``````