But so no commands exist to directly convert a float number from a value like 1.5641 to a value like 1.5 ??
No, because the Arduino, and every other computer on the planet, stores data in binary. Float values are only approximated. 1.5 can be approximated exactly. 1.4 can not.
aldoz:
You see I just to check ONLY until the number after the comma!
Floating point numbers have only a comma after formatting the number to a string.
If doing international formatting, there also will not be a decimal comma, but a decimal point.
In some countries like Germany a decimal comma is used more often, so for human readable output you might format strings with decimal comma instead of decimal point.
In case of floating point comparisons you usually have to define a range of the number, using a small value of 'epsilon' as the allowed variation.
So perhaps you might want to do something like:
const float epsilon=0.05;
if (x<1.5-epsilon) // value is less than 1.45
{
// ...
}
else if (x>=1.5+epsilon) // value is equal or more than 1.55
{
// ...
}
else // value is in the range 1.45 and less than 1.55
{
// ...
}
It would. But, if the original value was 1.4641, converting that to a string, 1.4, and back to a float would NOT result in the value 1.4 being stored in the float. Maybe 1.400001 or 1.39999, but NOT 1.4.
My big problem is that the value of the float X variable is not handled or set by me.
This value can be:
1.5641 or 1.61300 or 1.7923 or 1.81127 etc etc
After that, there are some events that start when these values are reached.
Example:
if (X == 1.5641) ----------> start event 1
if (X == 1.61300) ---------> start event 2
if (X == 1.7923) ----------> start event 3
if (X == 1.81127) ---------> start event 4
Just I would to obtain the following and have my program run correctly:
if (X == 1.5) ----------> start event 1
if (X == 1.6) ----------> start event 2
if (X == 1.7) ----------> start event 3
if (X == 1.8) ----------> start event 4
Or just make a math convert to obtain (example) 1.81127 in 1.8!