Show at least one decimal digit

This commit is contained in:
barsdeveloper
2022-04-27 21:28:37 +02:00
parent df518ccd3c
commit db0e3d0801
7 changed files with 65 additions and 30 deletions

View File

@@ -5,7 +5,7 @@ import TypeInitialization from "./entity/TypeInitialization"
export default class Utility {
static sigmoid(x, curvature = 1.7) {
return 1 / (1 + (x / Math.pow(1 - x, -curvature)))
return 1 / (1 + (x / (1 - x) ** -curvature))
}
static clamp(val, min, max) {
@@ -16,6 +16,19 @@ export default class Utility {
return Number(getComputedStyle(element).getPropertyValue("--ueb-scale"))
}
/**
* @param {Number} num
* @param {Number} decimals
*/
static minDecimals(num, decimals = 1) {
const powered = num * 10 ** decimals
if (Math.abs(powered % 1) > Number.EPSILON) {
// More decimal digits than required
return num.toString()
}
return num.toFixed(decimals)
}
/**
* @param {Number[]} viewportLocation
* @param {HTMLElement} movementElement