Because you are printing a float and by default .print will show 2 decimal places. Look up in the Arduino Reference for .print how to specify the extra parameter to tell it how many decimals you want.
As you are not showing any examples of output you get (what do your get? what are you expecting?) then if the answer is zero then it will print zero for the decimals.
I can't help as I don't immediately see the problem. I suggest that you add some serial prints to see what the actual values are that you read and calculate.
And it's strongly suggested to stay away from String (capital S); this is specifically the case when your program grows and does a lot of String manipulation which can result in memory fragmentation and unexpected behaviour at run time.
I'm not familiar with the STM32, so not sure if the following applies to that particular processor, but the map function uses integer math so will always produce a whole number as the output:
long map(long x, long in_min, long in_max, long out_min, long out_max) {
return (x - in_min) * (out_max - out_min) / (in_max - in_min) + out_min;
}
Simple enough to create your own function that uses floating point numbers.
david_2018:
I'm not familiar with the STM32, so not sure if the following applies to that particular processor, but the map function uses integer math so will always produce a whole number as the output:
long map(long x, long in_min, long in_max, long out_min, long out_max) {
So if your project requires precise calculations (e.g. voltage accurate to 3 decimal places), please consider avoiding map() and implementing the calculations manually in your code yourself.