C#: divide an int by 100

When one integer is divided by another, the arithmetic is performed as integer arithmetic. If you want it to be performed as float, double or decimal arithmetic, you need to cast one of the values appropriately. For example: decimal y = ((decimal) x) / 100; Note that I’ve changed the type of y as well … Read more

Dividing two integers to a double in java

This line here d = w[L] /v[L]; takes place over several steps d = (int)w[L] / (int)v[L] d=(int)(w[L]/v[L]) //the integer result is calculated d=(double)(int)(w[L]/v[L]) //the integer result is cast to double In other words the precision is already gone before you cast to double, you need to cast to double first, so d = ((double)w[L]) … Read more

Divide two variables in bash

shell parsing is useful only for integer division: var1=8 var2=4 echo $((var1 / var2)) output: 2 instead your example: var1=3 var2=4 echo $((var1 / var2)) ouput: 0 it’s better to use bc: echo “scale=2 ; $var1 / $var2” | bc output: .75 scale is the precision required