commit 84244f925c289cdbe8f56670750ac698f4f34394
parent 099469040ff4b58e2498482d228e70bb89a41652
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date: Wed, 9 Oct 2024 19:46:53 -0700
Add another mode to units separate method
Now you can decide whether to split the fraction into a unitless
array item or to use a floating point number.
Diffstat:
1 file changed, 3 insertions(+), 4 deletions(-)
diff --git a/files/floorplans/floorplan/editor.js b/files/floorplans/floorplan/editor.js
@@ -225,7 +225,8 @@ class Units {
return name
}
- separate(units, system) {
+ separate(units, system, options) {
+ options = options ?? {}
let parts = []
let unit = this.biggest(this.systems[system])
@@ -233,14 +234,12 @@ class Units {
let n = this.get(unit)
if (units >= n) {
let amount = units / n
- if (this.data[unit].base) {
+ if (this.data[unit].base || options.whole) {
amount = Math.floor(amount)
}
units -= amount * n // not sure about floating mod in js
parts.push({ unit: unit, symbol: this.data[unit].symbol, amount: amount })
}
-
-
} while (units > 0 && (unit = this.data[unit].base))
if (units > 0) {
parts.push({ "amount": units })