It technically depends on the language, but almost all languages ββrelate to this issue the same way. When there is a type mismatch between two data types in an expression, most languages ββwill try to pass data on the one hand = to match the data on the other hand according to a set of predefined rules.
When dividing two numbers of the same type (integers, doubles, etc.), the result will always be of the same type (so that "int / int" will always be int).
In this case, you have double var = integer result which, after calculating, calculates the integer result in double, in which case fractional data is already lost. (most languages ββwill do this casting to prevent type inaccuracies without throwing an exception or error).
If you want to save the result as double, you will want to create a situation in which you double var = double result
The easiest way to do this is to force the expression on the right side of the equation to double reset:
c = a/(double)b
Separating between an integer and a double result will cause the integer to be double (note that when doing math, the compiler often βjumpsβ to the most specific data type to prevent data loss).
After overheating, a will end as a double, and now you have a separation between the two doubles. This will create the desired division and purpose.
AGAIN,, please note that this is specific to the language (and may even be specific to the compiler), however, almost all languages ββ(of course, everything that I can think of from the head) consider this example to be identical.
matthewdunnam Sep 27 2018-11-11T00: 00Z
source share