Sign Up for Free

RunKit +

Try any Node.js package right in your browser

This is a playground to test code. It runs a full Node.js environment and already has all of npm’s 400,000 packages pre-installed, including round.js with all npm packages installed. Try it out:

var roundJs = require("round.js")

This service is provided by RunKit and is not affiliated with npm, Inc or the package authors.

round.js v1.1.1

round.js

Build Status Coverage Status Code Climate

Round a number to a specific number, by decimal or nearest

Installation

Install the package from npm

$ npm install --save round.js

Usage

import round from 'round.js';

round(1.234, 2);
//=> 1.23

round.up(1.234, 2);
//=> 1.24

round.down(1.234, 2);
//=> 1.23

round.to(11, 5);
//=> 10

round.next(11, 10);
//=> 20

round.prev(11, 10);
//=> 10

API

round.js: Tiny number-parser lib

Returns Number

round

Rounds a floating number to nearest number / float based on precision

Parameters

  • Number
  • precision
round(1.234, 2);
//=> 1.23

round.up

Rounds a floating up number to nearest number / float based on precision

Parameters

  • Number
  • precision
round.up(1.234, 2);
//=> 1.24

round.down

Rounds a floating down number to nearest number / float based on precision

Parameters

  • Number
  • precision
round.down(1.234, 2);
//=> 1.23

round.near

Increment or decrement the number until it reaches the nearest near number

Parameters

  • Number
  • near
round.near(11, 5);
//=> 10

round.near(13, 5);
//=> 15

round.next

Increment the number until it reaches the next next number

Parameters

  • Number
  • next
round.next(11, 5);
//=> 15

round.prev

Decrement the number until it reaches the previous prev number

Parameters

  • Number
  • prev
round.prev(11, 5);
//=> 10
RunKit is a free, in-browser JavaScript dev environment for prototyping Node.js code, with every npm package installed. Sign up to share your code.
Sign Up for Free