Skip to content
This repository was archived by the owner on Apr 12, 2024. It is now read-only.
This repository was archived by the owner on Apr 12, 2024. It is now read-only.

Broken ngStep for input[type="number"] directive #15504

Closed
@lucassus

Description

@lucassus

Do you want to request a feature or report a bug?

It's a bug

What is the current behavior?

For values like 1.16, 20.1 etc the input[type=number] field with ng-step="0.01" is marked as invalid.

Steps to reproduce:

  1. Update to AngularJS version 1.6.0
  2. Define an input[type=number] with ng-step="0.01"
  3. For values like 1.16, 20.1 the field will be marked as $invalid

See a small demo: https://plnkr.co/edit/LW2BsaA7FfEVu9nB6RoG?p=preview

I believe it's a problem with floating points arithmetic and this little method https://github.com/angular/angular.js/blob/master/src/ng/directive/input.js#L1563

    // ...

    value = value * multiplier;
    stepBase = stepBase * multiplier;
    step = step * multiplier;
  }

  return (value - stepBase) % step === 0;

When for instance value = 1.16 and multiplier = 100 value * multiplier gives us 115.99999999999999 so the return expression returns false even when the given value is valid.

Metadata

Metadata

Assignees

No one assigned

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions