Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

round-to

Package Overview
Dependencies
Maintainers
1
Versions
8
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

round-to - npm Package Compare versions

Comparing version 3.0.0 to 4.0.0

index.d.ts

21

index.js
'use strict';
function round(method, input, precision) {
if (typeof input !== 'number') {
function round(method, number, precision) {
if (typeof number !== 'number') {
throw new TypeError('Expected value to be a number');

@@ -12,18 +12,19 @@ }

const isRoundingAndNegative = method === 'round' && input < 0;
const isRoundingAndNegative = method === 'round' && number < 0;
if (isRoundingAndNegative) {
input = Math.abs(input);
number = Math.abs(number);
}
let [number, exponent] = `${input}e`.split('e');
let ret = Math[method](`${number}e${Number(exponent) + precision}`);
let exponent;
[number, exponent] = `${number}e`.split('e');
let result = Math[method](`${number}e${Number(exponent) + precision}`);
[number, exponent] = `${ret}e`.split('e');
ret = Number(`${number}e${Number(exponent) - precision}`);
[number, exponent] = `${result}e`.split('e');
result = Number(`${number}e${Number(exponent) - precision}`);
if (isRoundingAndNegative) {
ret = -ret;
result = -result;
}
return ret;
return result;
}

@@ -30,0 +31,0 @@

{
"name": "round-to",
"version": "3.0.0",
"version": "4.0.0",
"description": "Round a number to a specific number of decimal places: `1.234` → `1.2`",

@@ -13,9 +13,10 @@ "license": "MIT",

"engines": {
"node": ">=6"
"node": ">=8"
},
"scripts": {
"test": "xo && ava"
"test": "xo && ava && tsd"
},
"files": [
"index.js"
"index.js",
"index.d.ts"
],

@@ -34,5 +35,6 @@ "keywords": [

"devDependencies": {
"ava": "*",
"xo": "*"
"ava": "^1.4.1",
"tsd": "^0.7.2",
"xo": "^0.24.0"
}
}

@@ -28,3 +28,3 @@ # round-to [![Build Status](https://travis-ci.org/sindresorhus/round-to.svg?branch=master)](https://travis-ci.org/sindresorhus/round-to)

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.

@@ -38,15 +38,15 @@ ```js

### roundTo(value, precision)
### roundTo(number, precision)
Round the decimals with [`Math.round`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/round).
### roundTo.up(value, precision)
### roundTo.up(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(value, precision)
### roundTo.down(number, precision)
Round down the decimals with [`Math.floor`](https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Math/floor).
#### value
#### number

@@ -59,3 +59,3 @@ Type: `number`

Type: `number` (integer)
Type: `number` (Integer)

@@ -62,0 +62,0 @@ Number of decimal places.

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc