Skip to content

Conversation

@lsamboretrorabbit
Copy link
Contributor

Fixes the bug in the Angular Material 'slider' component.
Changed the function in the calculation from .floor to .round
Due to floating-point precision in JavaScript. (1 - 0.9) / 0.1 evaluates to 0.9999999999999999
Even though mathematically it should be 1
The calculation in the code resulted in slightly smaller value.
Math.floor(0.9999999999999999) evaluates to 0.
Math.round(0.9999999999999999) evaluates to 1.

Fixes #29084

…anged (for a step that is decimal number)

Fixes the bug in the Angular Material 'slider' component.
Changed the function in the calculation from .floor to .round
Due to floating-point precision in JavaScript. (1 - 0.9) / 0.1 evaluates to 0.9999999999999999
Even though mathematically it should be 1
The calculation in the code resulted in slightly smaller value.
Math.floor(0.9999999999999999) evaluates to 0.
Math.round(0.9999999999999999) evaluates to 1.

Fixes angular#29084
@crisbeto crisbeto removed the request for review from devversion May 29, 2024 11:32
@crisbeto crisbeto added action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release labels May 29, 2024
@crisbeto crisbeto self-assigned this May 29, 2024
@crisbeto crisbeto merged commit 3314414 into angular:main May 30, 2024
crisbeto pushed a commit that referenced this pull request May 30, 2024
…anged (for a step that is decimal number) (#29108)

Fixes the bug in the Angular Material 'slider' component.
Changed the function in the calculation from .floor to .round
Due to floating-point precision in JavaScript. (1 - 0.9) / 0.1 evaluates to 0.9999999999999999
Even though mathematically it should be 1
The calculation in the code resulted in slightly smaller value.
Math.floor(0.9999999999999999) evaluates to 0.
Math.round(0.9999999999999999) evaluates to 1.

Fixes #29084

(cherry picked from commit 3314414)
@shammy8
Copy link

shammy8 commented May 30, 2024

Hey can this change be merged into v17 as well please?

@angular-automatic-lock-bot
Copy link

This issue has been automatically locked due to inactivity.
Please file a new issue if you are encountering a similar or related problem.

Read more about our automatic conversation locking policy.

This action has been performed automatically by a bot.

@angular-automatic-lock-bot angular-automatic-lock-bot bot locked and limited conversation to collaborators Jun 30, 2024
Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.

Labels

action: merge The PR is ready for merge by the caretaker target: patch This PR is targeted for the next patch release

Projects

None yet

Development

Successfully merging this pull request may close these issues.

bug(slider): Tick marks changes position as the slider is changed

3 participants