Comparing version 5.0.0 to 6.0.0
@@ -1,56 +0,52 @@ | ||
declare const roundTo: { | ||
/** | ||
Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round). | ||
/** | ||
Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round). | ||
Numbers are rounded to a specific number of fractional digits. Specifying a negative `precision` will round to any number of places to the left of the decimal. | ||
Numbers are rounded to a specific number of fractional digits. Specifying a negative `precision` will round to any number of places to the left of the decimal. | ||
@param number - Number to adjust. | ||
@param precision - (Integer or Infinity) Number of decimal places. | ||
@param number - The number to adjust. | ||
@param precision - The number of decimal places. (Integer or Infinity) | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
@example | ||
``` | ||
import {roundTo} from 'round-to'; | ||
roundTo(1.234, 2); | ||
//=> 1.23 | ||
roundTo(1.234, 2); | ||
//=> 1.23 | ||
roundTo(1234.56, -2); | ||
//=> 1200 | ||
``` | ||
*/ | ||
(number: number, precision: number): number; | ||
roundTo(1234.56, -2); | ||
//=> 1200 | ||
``` | ||
*/ | ||
export function roundTo(number: number, precision: number): number; | ||
/** | ||
Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil). | ||
/** | ||
Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil). | ||
@param number - Number to adjust. | ||
@param precision - (Integer or Infinity) number of decimal places. | ||
@param number - The number to adjust. | ||
@param precision - The number of decimal places. (Integer or Infinity) | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
@example | ||
``` | ||
import {roundToUp} from 'round-to'; | ||
roundTo.up(1.234, 2); | ||
//=> 1.24 | ||
``` | ||
*/ | ||
up(number: number, precision: number): number; | ||
roundToUp(1.234, 2); | ||
//=> 1.24 | ||
``` | ||
*/ | ||
export function roundToUp(number: number, precision: number): number; | ||
/** | ||
Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). | ||
/** | ||
Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). | ||
@param number - Number to adjust. | ||
@param precision - (Integer or Infinity) number of decimal places. | ||
@param number - The number to adjust. | ||
@param precision - The number of decimal places. (Integer or Infinity) | ||
@example | ||
``` | ||
import roundTo = require('round-to'); | ||
@example | ||
``` | ||
import {roundToDown} from 'round-to'; | ||
roundTo.down(1.234, 2); | ||
//=> 1.23 | ||
``` | ||
*/ | ||
down(number: number, precision: number): number; | ||
}; | ||
export = roundTo; | ||
roundToDown(1.234, 2); | ||
//=> 1.23 | ||
``` | ||
*/ | ||
export function roundToDown(number: number, precision: number): number; |
12
index.js
@@ -1,3 +0,1 @@ | ||
'use strict'; | ||
function round(method, number, precision) { | ||
@@ -8,3 +6,3 @@ if (typeof number !== 'number') { | ||
if (precision === Infinity) { | ||
if (precision === Number.POSITIVE_INFINITY) { | ||
return number; | ||
@@ -24,3 +22,3 @@ } | ||
let result = Math[method](Number((number * power).toPrecision(15))) / power; | ||
let result = Math[method]((number * power).toPrecision(15)) / power; | ||
@@ -34,4 +32,4 @@ if (isRoundingAndNegative) { | ||
module.exports = round.bind(undefined, 'round'); | ||
module.exports.up = round.bind(undefined, 'ceil'); | ||
module.exports.down = round.bind(undefined, 'floor'); | ||
export const roundTo = round.bind(undefined, 'round'); | ||
export const roundToUp = round.bind(undefined, 'ceil'); | ||
export const roundToDown = round.bind(undefined, 'floor'); |
{ | ||
"name": "round-to", | ||
"version": "5.0.0", | ||
"version": "6.0.0", | ||
"description": "Round a number to a specific number of decimal places: `1.234` → `1.2`", | ||
@@ -13,4 +13,6 @@ "license": "MIT", | ||
}, | ||
"type": "module", | ||
"exports": "./index.js", | ||
"engines": { | ||
"node": ">=10" | ||
"node": "^12.20.0 || ^14.13.1 || >=16.0.0" | ||
}, | ||
@@ -27,3 +29,2 @@ "scripts": { | ||
"number", | ||
"num", | ||
"decimal", | ||
@@ -34,9 +35,10 @@ "places", | ||
"math", | ||
"increment" | ||
"increment", | ||
"precision" | ||
], | ||
"devDependencies": { | ||
"ava": "^2.4.0", | ||
"tsd": "^0.13.1", | ||
"xo": "^0.34.1" | ||
"ava": "^3.15.0", | ||
"tsd": "^0.18.0", | ||
"xo": "^0.46.4" | ||
} | ||
} |
@@ -1,2 +0,2 @@ | ||
# round-to [![Build Status](https://travis-ci.com/sindresorhus/round-to.svg?branch=master)](https://travis-ci.com/github/sindresorhus/round-to) | ||
# round-to | ||
@@ -7,5 +7,5 @@ > Round a number to a specific number of decimal places: `1.234` → `1.2` | ||
```sh | ||
npm install round-to | ||
``` | ||
$ npm install round-to | ||
``` | ||
@@ -15,3 +15,3 @@ ## Usage | ||
```js | ||
const roundTo = require('round-to'); | ||
import {roundTo, roundToUp, roundToDown} from 'round-to'; | ||
@@ -21,6 +21,6 @@ roundTo(1.234, 2); | ||
roundTo.up(1.234, 2); | ||
roundToUp(1.234, 2); | ||
//=> 1.24 | ||
roundTo.down(1.234, 2); | ||
roundToDown(1.234, 2); | ||
//=> 1.23 | ||
@@ -49,7 +49,7 @@ ``` | ||
### roundTo.up(number, precision) | ||
### roundToUp(number, precision) | ||
Round up the decimals with [`Math.ceil`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/ceil). | ||
### roundTo.down(number, precision) | ||
### roundToDown(number, precision) | ||
@@ -62,3 +62,3 @@ Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor). | ||
Number to adjust. | ||
The number to adjust. | ||
@@ -69,2 +69,2 @@ #### precision | ||
Number of decimal places. | ||
The number of decimal places. |
Yes
5404
63