simple-common-utils
Advanced tools
Comparing version 1.1.0 to 1.2.0
@@ -150,8 +150,16 @@ export default class StaticUtils { | ||
static round(value, decimals) { | ||
static round(value, decimals, symmetric) { | ||
// https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary | ||
// MarkG's answer. | ||
return decimals == undefined ? value : Number(Math. | ||
round(value + "e" + decimals) + "e-" + decimals); | ||
let result = value; | ||
if (decimals != undefined) { | ||
const multiplier = !symmetric ? undefined : result < 0 ? -1 : 1; | ||
result = Number(Math.round((multiplier ? Math.abs(result) : result) + | ||
"e" + decimals) + "e-" + decimals) * (multiplier || 1); | ||
} | ||
return result; | ||
} | ||
@@ -158,0 +166,0 @@ |
{ | ||
"name": "simple-common-utils", | ||
"version": "1.1.0", | ||
"version": "1.2.0", | ||
"description": "A collection of utility classes.", | ||
@@ -5,0 +5,0 @@ "main": "index.js", |
@@ -147,5 +147,5 @@ This is a collection of utility classes used for JS development. | ||
Rounds `value` to `decimals` digits after the decimal point. Thanks [MarkG](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary)! | ||
Rounds `value` to `decimals` digits after the decimal point (thanks, [MarkG](https://stackoverflow.com/questions/11832914/round-to-at-most-2-decimal-places-only-if-necessary)!). `symmetric` is used to achieve the same functionality both for negative and positive numbers. | ||
StaticUtils.round(value, decimals); | ||
StaticUtils.round(value, decimals, symmetric); | ||
@@ -157,2 +157,4 @@ StaticUtils.round(10.2); // 10.2 | ||
StaticUtils.round(10.525, 2); // 10.53 | ||
StaticUtils.round(-1.5, 0); // -1 | ||
StaticUtils.round(-1.5, 0, true); // -2 | ||
@@ -236,2 +238,3 @@ - encodedUtf8ToByteArray() | ||
-|- | ||
v1.2.0|The parameter `symmetric` is added to `StaticUtils.round()` in a backwards-compatible way. | ||
v1.1.0|The methods `StaticUtils.deg2Rad()` and `StaticUtils.color()` are added. | ||
@@ -238,0 +241,0 @@ v1.0.0|Initial release. |
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
License Policy Violation
LicenseThis package is not allowed per your license policy. Review the package's license to ensure compliance.
Found 1 instance in 1 package
19184
289
240