In the BME280 example they divide the pressure by 100 to convert to hPa.
But I don't understand why 100.0, why not 100 and what is that "F" after that?
It means [u]floating point[/u] but I've forgotten when/why it's important to add it.
But isn't it the same if you divide a float with integer 100 or float 100?
No, it is not the same.
long number = 10234;
void setup()
{
Serial.begin(115200);
Serial.println(number / 100); // integer divide
Serial.println(number / 100.0); // floating point divide
Serial.println(number / 100.0F); // the F does nothing, leave it off
//Serial.println(number / 100F); // causes the error
//unable to find numeric literal operator 'operator""F'
}
void loop()
{
}
102
102.34
102.34
tosoki_tibor:
But isn't it the same if you divide a float with integer 100 or float 100?
Yes, but it saves the reader from having to look up what kind of value bme.readPressure() returns.
Note: A number with a decimal point is, by default, type 'double'. The 'F' would make it a 'float' instead. I think you can have overloaded functions which takes either a 'float' or a 'double' for a particular argument. If you pass a numeric constant with a decimal point, the 'double' version will be called. To call the 'float' version you would have to explicitly add the 'F' (or 'f') after the constant to indicate it should be treated as a 'float'. Casting to 'float' would also work.
You can make it a 'long double' with the letter 'L'.
Thank You!