MikeMcl / decimal.js

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

Documantation problem #139

Closed uomopalese closed 5 years ago

uomopalese commented 5 years ago

From documentation:

In all examples below, var, semicolons and toString calls are not shown. If a commented-out value is in quotes it means toString has been called on the preceding expression.

I'm a low level user, and is difficult for me to understand your choice to put only part of the example and let users imagine the rest.. I mean, I can understand where to put var and semicolons. e.g.:

x = new Decimal(123.4567)
y = new Decimal('123456.7e-3')
z = new Decimal(x)
x.equals(y) && y.equals(z) && x.equals(z)        // true 

becomes

var x = new Decimal(123.4567);
var y = new Decimal('123456.7e-3');
var z = new Decimal(x);
var p = x.equals(y) && y.equals(z) && x.equals(z)        // true
console.log(p);       //true

but it's a bit more difficult to get this:

If a commented-out value is in quotes it means toString has been called on the preceding expression.

In this example:

var x = new Decimal('0xff.f')            // '255.9375'`

but

console.log(toString(x));            // returns [object Undefined] 

where have been called toString then? Thank you

MikeMcl commented 5 years ago

I sympathise, but it's as simple as:

new Decimal('0xff.f').toString()
// "255.9375"

or, more clearly,

(new Decimal('0xff.f')).toString()
// "255.9375"

or

var x = new Decimal('0xff.f')
x.toString()
// "255.9375"

You can try this by opening a browser console at the documentation page here.

uomopalese commented 5 years ago

You're right, is that simple... Thank you