The crux of the problem is further down, if you want to skip the background.
Background: I have code that I'm compiling for both an UNO (328) and an ATTiny85, in which I define a version number, and extract the integer and decimal parts to flash on two different LEDs on boot. E.g., version 4.1 flashes LED1 four times, and LED2 once. For some version numbers (e.g., 0.9, 1.1) this works fine. For others, it does not (e.g., 1.3, 3.1, 3.6, ...) There does not seem to be a pattern. I have stripped away all the code to the bare bones, and here's what I've found. I know this makes no sense, so I'd be grateful for someone to point out where I'm missing something. I'm pretty capable, and I've thought a lot about it and can't figure it out, so thanks for your time. I've also had my brother verify the same behaviour on his UNO, different computer, different city.
Crux: the following is standalone code, compiled in VSC Arduino for UNO (328) and uploaded via USB cable. It has also been tested compiled for an ATtiny85 and flashed via a USBasp. This is the entire code, followed by the output. I know there's a lot of redundancy; I was testing things grasping for straws.
#define VERSION 3.1
void setup() {
Serial.begin(19200);
byte decimal_b = (byte)((VERSION-(int)VERSION)*10);
int decimal_i = (int)((VERSION-(int)VERSION)*10);
float decimal_f = (float)((VERSION-(int)VERSION)*10);
Serial.println((VERSION-(int)VERSION)*10);
Serial.println(decimal_b);
Serial.println(decimal_i);
Serial.println(decimal_f);
Serial.println((int)decimal_f);
Serial.println((byte)decimal_f);
}
void loop() {}
When VERSION is 3.1:
[Info] Opened the serial port - COM12
1.00
0
0
1.00
0
0
When VERSION is 3.2:
[Info] Opened the serial port - COM12
2.00
2
2
2.00
2
2
I tested version numbers 1.X and 3.X where X=0..9. There seems to be no pattern. The following "work" in that the (int) cast is as expected (2 for version 3.2):
1.1, 1.2, 1.5, 1.6, 1.7, 1.9, 1.0
3.2, 3.4, 3.5, 3.7, 3.9, 3.0
The others do not work, in that the decimal is one less than expected given the version number.