junkfix / numberbox-card

Replace input_number sliders with plus and minus buttons
109 stars 9 forks source link

unit=time: wrong data displayed #58

Closed ildar170975 closed 2 years ago

ildar170975 commented 2 years ago

Consider this example:

type: entities
entities:
  - entity: input_number.test_negative_1
    name: standard
  - type: custom:numberbox-card
    entity: input_number.test_negative_1
    name: unit=time (with ss)
    unit: time
  - type: custom:numberbox-card
    entity: input_number.test_negative_1
    name: unit=timehm
    unit: timehm
  test_negative_1: &ref_test_nagative_values
    min: -10000000
    max: 10000000
    step: 0.1
    mode: box

Output is: изображение

  1. A value for "seconds" is wrong - it must be "4.4".
  2. Imho the "seconds" value should be rounded.
ildar170975 commented 2 years ago
t += ':' + Math.floor(x%60).toString().padStart(2,'0');

Can we have a rounding here instead of just "floor"?

htmltiger commented 2 years ago

rounding of 59.6 would display 60 would be confusing

ildar170975 commented 2 years ago

From another side, conversion from float to hh:mm:ss should be mathematically as precise as possible ...

htmltiger commented 2 years ago

this would be ok

    x=Math.round(x);
    t = (x>=3600 || f)? Math.floor(x/3600).toString().padStart(2,'0') + ':' : '';
    t += (Math.floor(x/60)-Math.floor(x/3600)*60).toString().padStart(2,'0');
    if( !u ){
        t += ':' + Math.round(x%60).toString().padStart(2,'0');
    }
    return t;
ildar170975 commented 2 years ago

Cannot verify it quickly, unfortunately, I am about C/C++ basically, know JS worse ((((

htmltiger commented 2 years ago

we round it first before processing so 59.6 would become 60 so will display as 01:00

ildar170975 commented 2 years ago

Very good! I will try to test all these cases when you create the updated release.

ildar170975 commented 2 years ago

Tested, seems to be OK! Thank you!