I am taking an input from a textbox from a user. That value is converted to a float using the following line:
float x = float.Parse(txt1.Text) * 8;
The float variable is then converted to an integer using the following line:
int switchOnDelayValue = (int)Math.Round(x);
Then I convert the integer into a hexadecimal equivalent string using:
valueToString = Convert.ToString(switchOnDelayValue, 16).PadLeft(8, '0');
The conversion from float to int works fine for mostly all values, except for some values near the maximum value of int. For example, when I input the value 268,435,455
float x = float.Parse(txt1.Text) * 8
x should now store 2,147,483,640. However, the float stores the value as 2.14748365E+09. And when the float is casted as an int, it overflows and gives a negative value.