Number fields drop trailing zeros: formatNumber still rounds to at most 3 decimals and then removes zeros at the end, so 100.000 reads 100 and 0.500 reads 0.5, everywhere (inspector, graph and shader nodes, duration and fps in the animation and tile tabs); a field's own decimals is now an upper limit, stored values are unchanged, -0 still shows as 0, and the graph's separate integer rule is gone (#172)
Co-Authored-By: Claude Opus 5 <noreply@anthropic.com>
This commit is contained in:
1 parent
47eea2f6e4
commit
4f546c0e08
6 files changed
+36
-17
No files matched your search
+4
-4
@@ -12,13 +12,13 @@ export function centreY(containerHeight: number, itemHeight: number): number {
|
||||
export const NUMBER_DECIMALS = 3;
|
||||
|
||||
/**
|
||||
* Always shows `decimals` places, so a value can never look whole when it is not. A value that
|
||||
* rounds to zero never carries a minus sign.
|
||||
* Rounds to `decimals` places and drops trailing zeros: `100`, `0.5`, `9.091`. A value that rounds
|
||||
* to zero never carries a minus sign.
|
||||
*/
|
||||
export function formatNumber(value: number, decimals = NUMBER_DECIMALS): string {
|
||||
const zero = (0).toFixed(decimals);
|
||||
const text = value.toFixed(decimals);
|
||||
return text === '-' + zero ? zero : text;
|
||||
const trimmed = text.includes('.') ? text.replace(/\.?0+$/, '') : text;
|
||||
return trimmed === '-0' ? '0' : trimmed;
|
||||
}
|
||||
|
||||
/** Rounds to `decimals` places, which also removes binary-float noise (0.1 × 3 = 0.30000000000000004). */
|
||||
|
||||
Reference in new issue
Block a user