I'm trying to declare a double in C# that has the value of a quotient. It doesn't seem to work...
double convert = 5 / 1024;
This keeps assigning the value 0 to the variable 'convert' instead of 0.0048828125.
I am using it in a serial read to convert the 10-bit integer back to a voltage...
static void Main(string[] args)
{
double rawValue;
double convert = 5 / 1024; // Assigns value of 0
double convValue;
string read;
SerialPort sp = new SerialPort("COM3"); // Creates COM port
sp.BaudRate = 9600;
sp.Open();
for (;;)
{
read = sp.ReadLine();
rawValue = Convert.ToDouble(read);
convValue = rawValue * convert;
Console.WriteLine(Math.Round(convValue, 2));
}
}
The serial read works fine; I can read and write to the console the 0-1023 number and then converter it manually. I just can't assign the conversion double with the expression "5 / 1024".