Skip to content

[Slider] Displayed slider values (minus valueFrom) are sometimes not integer multiples of stepsize due to floating point arithmetic #4978

@capmlbpkel

Description

@capmlbpkel

Description:

  1. Open slider
  2. Slide to 2.65x
  3. Value is shown as 2.6499999x

Expected behavior:

Value is shown as 2.65x (rounding would mitigate the issue)

Source code: Taken from https://github.com/libre-tube/LibreTube/blob/master/app/src/main/res/layout/playback_bottom_sheet.xml:

                        <com.google.android.material.slider.Slider
                            android:id="@+id/speed"
                            android:layout_width="match_parent"
                            android:layout_height="wrap_content"
                            android:stepSize="0.05"
                            android:value="1.0"
                            android:valueFrom="0.2"
                            android:valueTo="4.0"
                            android:layout_marginTop="5dp"
                            android:layout_marginHorizontal="10dp" />

Minimal sample app repro: Not a minimal example since I do not develop for android, but a repo where the problem occurs: https://github.com/libre-tube/LibreTube. Related issue: libre-tube/LibreTube#7949

Android API version: 35 (taken from https://github.com/libre-tube/LibreTube/blob/master/app/build.gradle.kts, I hope this is correct)

Material Library version: 1.14.0-alpha06

Device: G7 Power / ocean

Metadata

Metadata

Assignees

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions