Disclaimer: I realize this is not the easiest or even best way to handle this and I am asking largely out of a sense of curiosity, not because I'm convinced this is the proper way. It's a fun puzzle I've been wrestling with for a day or so now and can't figure out (and can't seem to find a good answer online either!)
I'm working on a project with my Arduino (but this could apply to any hardware) which involves sensing temperature. I get the value, parse it, and have it stored in Celsius with a 1/100 scaling factor. e.g. the value 5.34C is stored in memory as the uint16_t 534
. Thus printing this value is a matter of print (temp / 100 + "." + temp % 100)
. When I use it for logic in my program I need only compare it against another value with a 1/100 scaling factor and everything works great.
Let's pretend my Arduino or whatever system had no support for floating point numbers and I only had integers. How can I convert this number to Fahrenheit? I've tried several times to work it out on paper and it seems right but I always get an incorrect result when testing.
5.34 / 5 * 9 + 32
is41.61
and534 / 5 * 9 + 32
is4161
– Gort the Robot Jun 19 '18 at 23:20