Fix faulty timestamp rounding to nearest integer (fixes #207)

This commit is contained in:
Vanilagy
2025-11-12 21:35:18 +01:00
parent 0f030dc2a6
commit 6684984e7e
4 changed files with 15 additions and 10 deletions
+8 -3
View File
@@ -486,9 +486,14 @@ export const clamp = (value: number, min: number, max: number) => {
export const UNDETERMINED_LANGUAGE = 'und';
export const roundToPrecision = (value: number, digits: number) => {
const factor = 10 ** digits;
return Math.round(value * factor) / factor;
export const roundIfAlmostInteger = (value: number) => {
const rounded = Math.round(value);
if (Math.abs(value / rounded - 1) < 10 * Number.EPSILON) {
return rounded;
} else {
return value;
}
};
export const roundToMultiple = (value: number, multiple: number) => {