JSPM

  • ESM via JSPM
  • ES Module Entrypoint
  • Export Map
  • Keywords
  • License
  • Repository URL
  • TypeScript Types
  • README
  • Created
  • Published
  • Downloads 3
  • Score
    100M100P100Q51022F
  • License MIT

Small function that rounds number with selected precision

Package Exports

  • @drag13/round-to

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 (@drag13/round-to) to support the "exports" field. If that is not possible, create a JSPM override to customize the exports field for this package.

Readme

RoundTo

codecov Build Status npm TypeSCript GitHub license

Description

Small one-function-lib to round numbers with custom precision. TypeScript ready.

Installation

npm install @drag13/round-to

Usage

RoundTo function rounds your decimal with selected precesion. It also tries to handle edge cases with floating point using Epsilon shift and nano-robots.

const round = require('@drag13/round-to');
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);

TypeScript

Feel free to use it with TypeScript

import * as round from '@drag13/round-to';
const roundingResult = round(5.4399, 2);
console.assert(roundingResult===5.44);

Tests

npm test

Some covered cases

console.assert(roundTo(0.43499999999999994, 2)===0.435);
console.assert(roundTo(Math.PI, 2)===3.14);

Contributing

Any bug fixing is appreciated. If you want to add new functionality - you're welcome. But KISS it please.