Skip to content

[Bug]: Draw template number fields reject valid decimals (e.g. 1.2 with step 0.1) due to floating-point step check #1129

Open

Description

@jl-0

Checked for duplicates

Yes - I've already checked

Describe the bug

When I save a Draw feature whose property template has a number field with a decimal step (e.g. step: 0.1), many valid values are rejected. Entering 1.2 and pressing Save All Changes shows:

This feature has invalid form values: 'canopy_height_m' must be a multiple of 0.1

and the feature is not saved.

The check in DrawTool_Templater.js (getTemplateValues, the number case; line ~427 on development) compares a floating-point quotient to its integer part:

values[t.field] / t.step != parseInt(values[t.field] / t.step)

In IEEE-754, 1.2 / 0.1 === 11.999999999999998, so parseInt gives 11 and the value is "not a multiple". For step: 0.1, 16 of the 50 values from 0.1 to 5.0 are rejected: 0.3, 0.6, 0.7, 1.2, 1.4, 1.9, 2.3, 2.4, 2.8, 2.9, 3.3, 3.8, 4.1, 4.3, 4.6, 4.8. step: 0.01 is affected the same way.

The user sees a validation error for a correct value and has no way to enter it.

What did you expect?

I expected any value that is a whole number of steps from 0 (to within floating-point tolerance) to be accepted. For example:

const q = values[t.field] / t.step
if (Math.abs(q - Math.round(q)) > 1e-9) invalids[t.field] = `'${t.field}' must be a multiple of ${t.step}`

(Relative to min rather than 0 may also be intended, as in HTML <input step>, but that is a separate question.)

Reproducible steps

1. Give a Draw file a template with: { "type": "number", "field": "h", "label": "Height", "min": 0, "max": 50, "step": 0.1 }
2. Draw a feature in that file and open its properties.
3. Enter 1.2 in Height and press "Save All Changes".
4. Toast: "This feature has invalid form values: 'h' must be a multiple of 0.1". Not saved.
   (1.5 or 1.0 save fine.)

# Quick check of the arithmetic:
node -e 'for(let i=1;i<=50;i++){const v=+(i/10).toFixed(1);if(v/0.1!=parseInt(v/0.1))console.log(v)}'

Environment

- MMGIS: present on `development` (5.3.15-20260825); the comparison dates from the original templates feature (#353)
- Seen on: iPad Pro 13" (2025), iOS 26.4, WKWebView; also reproducible in any browser, as it is pure arithmetic

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions