convert icon indicating copy to clipboard operation
convert copied to clipboard

Unexpected result using your example of converting 36 hours to "best" units

Open Eric24 opened this issue 1 year ago • 1 comments

console.log(convert(36, 'h').to('days').toString());
'1.5'

console.log(convert(36, 'h').to('days'));
1.5

console.log(convert(36, 'h').to('best').toString());  // your example of using 'best'
'1.4999999999999998d'

console.log(convert(36, 'h').to('best'));
{
  quantity: 1.4999999999999998,
  unit: 'd',
  toString: ƒ ()
}

Eric24 avatar Dec 25 '23 23:12 Eric24

Hi! Thanks for making the report, I'm currently not feeling super well at the moment, but I should be able to take a look at it in a few days/this weekend.

The reason this behavior happens is because the math used internally is very slightly different when you convert to the best unit, hence the inconsistent results. I can likely fix this fairly easily by just making a call to the main conversion code when converting to the best unit, instead of having two separate implementations.

jonahsnider avatar Dec 27 '23 18:12 jonahsnider

:tada: This issue has been resolved in version 4.14.1 :tada:

The release is available on:

Your semantic-release bot :package::rocket:

jonahsnider avatar Jan 09 '24 05:01 jonahsnider