float round1dp(float f)
{
float f1 = int(f * 10.0f + (signbit(f) ? -0.5f : +0.5f)) / 10.0f;
Serial.print(f, 3);
Serial.print("\t");
Serial.println(f1, 3);
return f1;
//return int(f * 10.0f + (signbit(f) ? -0.5f : +0.5f)) / 10.0f;
//return int(f * 10.0f + (f < 0 ? -0.5f : +0.5f)) / 10.0f;
}
void setup()
{
// put your setup code here, to run once:
Serial.begin(115200);
float floats[] = { -10.00f, -9.56f, -9.55f, -9.54, +10.00f, +9.56f, +9.55f, +9.54 };
for (const auto f : floats)
{
float f1 = round1dp(f);
}
for (float f = -10.0f; f < +10.0f; f += 0.01)
{
float f1 = round1dp(f);
}
Serial.flush();
}
void loop()
{
// put your main code here, to run repeatedly:
}