convert
convert copied to clipboard
Unexpected result using your example of converting 36 hours to "best" units
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: ƒ ()
}
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.
:tada: This issue has been resolved in version 4.14.1 :tada:
The release is available on:
Your semantic-release bot :package::rocket: