www.spaceplanner.app

Web client to the spaceplanner API
git clone git://jacobedwards.org/www.spaceplanner.app
Log | Files | Refs

commit 6c62a16d562bc487e7cdfc9357022e8f0a4457ec
parent 84244f925c289cdbe8f56670750ac698f4f34394
Author: Jacob R. Edwards <jacob@jacobedwards.org>
Date:   Wed,  9 Oct 2024 19:48:13 -0700

Show limited fractional lengths in userLength

Diffstat:
Mfiles/floorplans/floorplan/main.js | 20+++++++++++++++++---
1 file changed, 17 insertions(+), 3 deletions(-)

diff --git a/files/floorplans/floorplan/main.js b/files/floorplans/floorplan/main.js @@ -1173,15 +1173,16 @@ function parseUserLength(editor, length) { } function userLength(editor, units) { - let a = editor.units.separate(units, editor.unitSystem) + let a = editor.units.separate(units, editor.unitSystem, { whole: false }) let words = [] for (let i in a) { if (!a[i].unit) { // We don't allow anything smaller than smallest defined unit, // though maybe this should be an error condition - continue } - words.push(String(a[i].amount) + (a[i].symbol ?? a[i].name)) + + words.push(a[i].amount.toFixed(Math.min(2, precision(a[i].amount))) + + (a[i].symbol ?? a[i].name ?? "")) } return words.join(" ") } @@ -1280,4 +1281,17 @@ function primaryMove(ev) { return ev.isPrimary } +function precision(a) { + if (!isFinite(a)) { + return 0; + } + let e = 1 + let p = 0 + while (Math.round(a * e) / e !== a) { + e *= 10 + p++ + } + return p +} + window.onload = init