Skip to content

[BUG] Rounding problem editing numbers on LCD #16866

@drifkind

Description

@drifkind

Bug Description

When editing some parameters on the LCD, the number loaded into the editor is wrong. (Close, bug not close enough.)

My Configurations

Ender-3 configuration from MarlinConfigurations.

marlin-config.zip

Steps to Reproduce

  1. Select Main --> Temperature --> Fan Speed.
  2. Set fan speed to (e.g.) 10%.
  3. Press knob to re-enter editor. Editor shows 9% instead of 10%.
  4. Repeat ad lib.

Also happens some other places, though not quite as easy to find. For example:

  1. Select Main --> Configuration --> Advanced --> Temperature --> Fact.
  2. Set factor to 0.30. (Or 0.60 or 0.90...)
  3. Press knob; editor shows 0.29.

Suggested Fix

--- a/Marlin/src/lcd/menu/menu.h
+++ b/Marlin/src/lcd/menu/menu.h
@@ -236,5 +236,5 @@ class TMenuEditItem : MenuEditItemBase {
     typedef typename NAME::type_t type_t;
     static inline float unscale(const float value)    { return value * (1.0f / NAME::scale);  }
-    static inline float scale(const float value)      { return value * NAME::scale;           }
+    static inline float scale(const float value)      { return roundf(value * NAME::scale);   }
     static void load(void *ptr, const int32_t value)  { *((type_t*)ptr) = unscale(value);     }
     static const char* to_string(const int32_t value) { return NAME::strfunc(unscale(value)); }

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions