JSPM

roundit

1.0.1
  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • 0
  • Score
    100M100P100Q23044F
  • License ISC

simple rounding library

Package Exports

  • roundit

This package does not declare an exports field, so the exports above have been automatically detected and optimized by JSPM instead. If any package subpath is missing, it is recommended to post an issue to the original package (roundit) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

roundit

javascript rounding library

A quick and simple rounding library, without resorting to string conversion, manipulation or other 3rd party maths routines.

Usage:

  var round = require('roundit');

  console.log('Round 5.125 to Nearest 2dp: ' + round.nearest(5.125, 2));
  console.log('Round 5.125 to Ceil 2dp: ' + round.ceil(5.125, 2));
  console.log('Round 5.125 to Floor 2dp: ' + round.floor(5.125, 2));
  console.log('Round 5.125 to Fix 2dp: ' + round.fix(5.125, 2));
  console.log('Round 5.125 to Infinite 2dp: ' + round.infinite(5.125, 2));

Rounding Options

nearest

Standard rounding to nearest number, >= 0.5 up, < 0.5 down.

  round.nearest(value to round, decimal places)
  1.5 to 0 decimal places => 2
  1.4 to 0 decimal places => 1
ceil

Always round up to larger significant digit (toward positive infinity).

  round.ceil(value to round, decimal places)
  1.5 to 0 decimal places => 2
  -1.5 to 0 decimal places => -1
floor

Always round up to smaller significant digit (toward negative infinity).

  round.floor(value to round, decimal places)
  1.5 to 0 decimal places => 1
  -1.5 to 0 decimal places => -2
fix

Always round towards zero.

  round.fix(value to round, decimal places)
  1.5 to 0 decimal places => 1
  -1.5 to 0 decimal places => -1
infinite

Always round away from zero (toward +-infinity).

  round.infinite(value to round, decimal places)
  1.5 to 0 decimal places => 2
  -1.5 to 0 decimal places => -2