From b6adacc19b1961ad5cb345b2726328113abdcb63 Mon Sep 17 00:00:00 2001 From: Varun Patil Date: Sat, 15 Oct 2022 20:33:07 -0700 Subject: [PATCH] timeline: floor dispWp instead of round --- src/components/Timeline.vue | 4 ++-- src/services/Utils.ts | 6 ++++-- 2 files changed, 6 insertions(+), 4 deletions(-) diff --git a/src/components/Timeline.vue b/src/components/Timeline.vue index 59f4d314..cdb2d032 100644 --- a/src/components/Timeline.vue +++ b/src/components/Timeline.vue @@ -337,7 +337,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { row.photos[j] = { flag: this.c.FLAG_PLACEHOLDER, fileid: Math.random(), - dispWp: utils.round(100 / this.numCols, 2), + dispWp: utils.round(100 / this.numCols, 2, true), }; } delete row.pct; @@ -721,7 +721,7 @@ export default class Timeline extends Mixins(GlobalMixin, UserConfig) { utils.convertFlags(photo); // Get aspect ratio - photo.dispWp = utils.round(100 * jbox.width / this.rowWidth, 2); + photo.dispWp = utils.round(100 * jbox.width / this.rowWidth, 2, true); // Move to next index of photo dataIdx++; diff --git a/src/services/Utils.ts b/src/services/Utils.ts index 9a3d20ed..4b8419c5 100644 --- a/src/services/Utils.ts +++ b/src/services/Utils.ts @@ -95,10 +95,12 @@ export function binarySearch(arr: any, elem: any, key?: string) { * Round a number to N decimal places * @param num Number to round * @param places Number of decimal places + * @param floor If true, round down instead of to nearest */ -export function round(num: number, places: number) { +export function round(num: number, places: number, floor=false) { const pow = Math.pow(10, places); - return Math.round(num * pow) / pow; + const int = num * pow; + return (floor ? Math.floor : Math.round)(int) / pow; } /**