Coder Social home page Coder Social logo

ml-numbers's Introduction

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

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.