Restore toFormat
The toFormat() method was removed a while ago in favor of a separate library, toFormat. Decimal.js feels incomplete without this method, and it seems strange to require a separate library for a single method. It's also unclear how to use this library with ESM. The developer ergonomics are just very odd.
@MikeMcl can you restore toFormat(), please?
Speak your mind, why don't you? :grin:
Please tell me more about why it's unclear how to use this library with ESM.
I will look at toFormat presently.
It's unclear because it's not documented, and naïvely changing the require() to an import won't work. I instead have to create a new class, which just seems wrong all to get one method that I honestly would expect to exist (although I haven't needed it until now, 3 years into my usage of the library).
import Decimal from 'decimal.js';
import toFormat from 'toformat';
// TS2632: Cannot assign to Decimal because it is an import.
Decimal = toFormat(Decimal);
const DecimalWithFormat = toFormat(Decimal);
const d = new DecimalWithFormat('1000.00');
console.log(d.toFormat(2)); // Prints 1,000.00
Subjectively: the developer ergonomics of requiring a new library that has to be configured in a non-ideal manner suck. That's me being honest about this specific situation, but still immensely grateful for the work that's been done. ❤️
Related-- I had no idea toFormat existed. Could this be added to the FAQ section of the docs?