How do I divide two integers to get a double?
相关问题
- Sorting 3 numbers without branching [closed]
- Graphics.DrawImage() - Throws out of memory except
- Why am I getting UnauthorizedAccessException on th
- 求获取指定qq 资料的方法
- How to know full paths to DLL's from .csproj f
You want to cast the numbers:
Note: If any of the arguments in C# is a
double
, adouble
divide is used which results in adouble
. So, the following would work too:For more information see:
Dot Net Perls
Convert one of them to a double first. This form works in many languages:
cast the integers to doubles.
Complementing the @NoahD's answer
To have a greater precision you can cast to decimal:
Or:
Double are represented allocating 64 bits while decimal uses 128
In depth explanation of "precision"
For more details about the floating point representation in binary and its precision take a look at this article from Jon Skeet where he talks about
floats
anddoubles
and this one where he talks aboutdecimals
.