int a=870,b0=-20, b1=120, a0=0, a1=3584;
double d=(b0 + (b1 - b0) * ((a - a0) / (a1 - a0)));
Console.Write(d);
It gives a result as -20
. I want it precisely upto few decimal places.
whats wrong with c#??
int a=870,b0=-20, b1=120, a0=0, a1=3584;
double d=(b0 + (b1 - b0) * ((a - a0) / (a1 - a0)));
Console.Write(d);
It gives a result as -20
. I want it precisely upto few decimal places.
whats wrong with c#??
You're using int
. If you want double precision, convert them to double
before doing division, or just simply define them as double in the first place. It's doing whole numbers division the way you wrote it.
you are doing operations between integers thus the result is an integer. Try:
double a=870,b0=-20, b1=120, a0=0, a1=3584;
double d=(b0 + (b1 - b0) * ((a - a0) / (a1 - a0)));
Console.Write(d);