MikeMcl / decimal.js

An arbitrary-precision Decimal type for JavaScript
http://mikemcl.github.io/decimal.js
MIT License
6.35k stars 480 forks source link

Implement Symbol.toPrimitive to solve issues with lexographical comparison #186

Open francisrstokes opened 2 years ago

francisrstokes commented 2 years ago

This PR implements the Symbol.toPrimitive method, which provides a strategy to convert a decimal to a number when comparisons like less than, greater than, etc.

This PR should close #172.

francisrstokes commented 2 years ago

This fix breaks some other tests - some of which are likely easy to accommodate for and some might need some more investigation. This PR is mostly to get the discussion started for allowing sane comparisons of Decimals.