timeline: floor dispWp instead of round

old-stable24
Varun Patil 2022-10-15 20:33:07 -07:00
parent 02059b52c9
commit 9863527bbb
2 changed files with 6 additions and 4 deletions

View File

@ -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++;

View File

@ -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;
}
/**