@mojaloop/ml-number
Mojaloop Number Library implementation that handles decimal processing of amounts/numbers
Last updated a year ago by l1pcircleci .
Apache-2.0 · Original npm · Tarball · package.json
$ cnpm install @mojaloop/ml-number 
SYNC missed versions from official npm registry.

ml-number

Git Commit Git Releases Npm Version NPM Vulnerabilities CircleCI

Mojaloop Number Library implementation that handles decimal processing of amounts/numbers

Getting Started

To use the ml-number library you need to add it as a dependency to your project with the following:

npm install @mojaloop/ml-number

Usage

To create a new instance of the MLNumber class(returns instance of MLNumber):

const MLNumber = require('@mojaloop/ml-number')
const mlNumber = new MLNumber(6) // can be instantiated with a number
const mlNumber2 = new MLNumber('6') // can be instantiated with a string
const mlNumber3 = new MLNumber(mlNumber2) // can be instantiated with a MLNumber

Use different function(returns new instance of new MLNumber):

const MLNumber = require('@mojaloop/ml-number')

const originalValue = new MLNumber(6) // = "{"MLNumber": "6"}"

const additionResult = originalValue.add(12) // = "{"MLNumber": "18"}"

const multiplyResult = originalValue.multiply('12') // = "{"MLNumber": "72"}"

const divisionResult = originalValue.divide(2) // = "{"MLNumber": "3"}"

const subtractionResult = originalValue.subtract('2') // = "{"MLNumber": "4"}"

const mixedFunctionsValuesResult = new MLNumber('2').add(originalValue).sumList([additionResult, 5]) // = "{"MLNumber": "31"}"

const differentFunctionsResult = originalValue.add(2).multiply(3).divide(2).subtract(2) // = "{"MLNumber": "10"}"

const sumListResult = originalValue.sumList([2,3]) // = "{"MLNumber": "11"}"

const toStringResult = additionResult.toString() // = "18"

const toNumberResult = multiplyResult.toNumber() // = 72

const toFixedResult = divisionResult.toFixed() // = "3.0000"

const toFixedWithDecimalPlaceResult = subtractionResult.toFixed(7) // = "4.0000000"

Running the tests

To run the unit tests locally

npm test

To run the test coverage tests locally

npm run test:coverage

Current Tags

  • 8.2.0                                ...           latest (a year ago)

2 Versions

  • 8.2.0                                ...           a year ago
  • 8.1.0                                ...           a year ago
Downloads
Today 0
This Week 0
This Month 0
Last Day 0
Last Week 0
Last Month 0
Dependencies (1)
Dev Dependencies (10)
Dependents (1)

Copyright 2014 - 2016 © taobao.org |