Giter Site home page Giter Site logo

node-math-precision's Introduction

math-precision

build status

This node.js package gives you a cleaner way to round numbers using pecision

e.g. To round 1.2347 with precision 2 you can call

math.round(1.2347, 2) = 1.23

instead of using something like

Math.round(1.2347 * 100) / 100 // = 1.23 (this is done beneath the function call .round(number, precision))

See other examples or run the tests

Install

$ npm i math-precision

Examples

round

var round = require('math-precision').round

console.log(round(1.2347, 2))        // 1.23
console.log(round(1.235, 2))         // 1.24
console.log(round(1.2, 2))           // 1.2

ceil

var ceil = require('math-precision').ceil

console.log(ceil(1.2347, 2))          // 1.24
console.log(ceil(1.2, 2))             // 1.2

floor

var floor = require('math-precision').floor

console.log(floor(1.2361, 2))         // 1.23
console.log(floor(1.8, 2))            // 1.8

using math object

var math = require('math-precision')

console.log(math.round(1.2358, 2))    // 1.24
console.log(math.ceil(1.2358, 2))     // 1.24
console.log(math.floor(1.2358, 2))    // 1.23

Test

Simply clone the repo, npm install, and run npm test

License

node-math-precision's People

Contributors

davidflorin avatar florindavid avatar

Watchers

 avatar  avatar

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.