Skip to content
Open
Changes from 1 commit
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
16 changes: 11 additions & 5 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -48,12 +48,17 @@ Note: ⚠️ All property/method names up for bikeshedding.

* `value` (Number or BigInt or String): The numerical value of the amount.
By default, the type of the value used in the constructor is retained.

The value of an Amount constructed with precision options,
or one that's the result of unit conversion,
is always a numerical string.
is always a numerical String if the value is finite,
using the same exponential notation as produced by [Number.p.toExponential],
or a Number if the value is `Infinity`, `-Infinity`, or `NaN`.
* `unit` (String or not defined): The unit of measurement associated with the Amount's numerical value.
An undefined value indicates "no unit supplied".

[Number.p.toExponential]: https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toExponential

### Constructor

* `new Amount(value[, options])`. Constructs an Amount with the numerical value of `value`
Expand All @@ -67,11 +72,11 @@ Note: ⚠️ All property/method names up for bikeshedding.
When constructing an Amount from a String `value`,
its mathematical value is parsed using [StringNumericLiteral](https://tc39.es/ecma262/#prod-StringNumericLiteral)
or a RangeError is thrown.
The `value` property of a String-valued Amount is not necessarily equal to the `value` its constructor was called with,
as it is always a [StrDecimalLiteral](https://tc39.es/ecma262/#prod-StrDecimalLiteral), or `"NaN"`.
The `value` property of a String-valued Amount is not necessarily equal to the `value` its constructor was called with.

If either `fractionDigits` or `significantDigits` is set,
the `value` is rounded accordingly, and is stored as a String.
the `value` is rounded accordingly,
and is stored as a String (if finite) or Number (if not finite).

The object prototype would provide the following methods:

Expand Down Expand Up @@ -102,7 +107,8 @@ The object prototype would provide the following methods:
`{ minimumFractionDigits: 0, maximumFractionDigits: 3}` is used.
If both fraction and significant digit options are set,
the resulting behaviour is selected by the `roundingPriority`.
The numerical value of the Amount resulting from unit conversion is stored as a String.
The numerical value of the Amount resulting from unit conversion is
stored as a String (if finite) or Number (if not finite).

Calling `convertTo()` will throw an error if conversion is not supported
for the Amount's unit (such as currency units),
Expand Down