floating
Simple wrapper for basic arithmetic—addition, subtraction, multiplication and division.
Useful for plugging it into arbitrary-precision or linear-arbitrary-precision as a fallback to specialised arbitrary precision libraries.
Install
npm i floating
Usage
Factory and configuration
var Floating = ; 1
Operations
01; // => 0.1 + 0.2 03; // => 0.3 - 0.1 06; // => 0.6 * 3 03; // => 0.3 / 0.2
toString, valueOf and toJSON
var floatingThird = 1; floatingThird; // => '0.3333333333333333' floatingThird === floatingThird; // => true NumberfloatingThird; // => 1/3
JSON.stringify and JSON.parse with reviver
var stringified = JSON; // => '0.3333333333333333' JSON; // => new Floating(0.3333333333333333)
See spec.
Related projects
- linear-converter: flexible linear converter with built in conversions for common units.
- linear-conversion: Linear conversion class for linear-converter.
- rescale: rescales a point given two scales.
- rescale-util: Rescale utilities.
- scale: scales normalised data.
- normalise: normalise data to [0, 1].