Closed gabrielgrant closed 6 years ago
Interesting idea. I'll try to take a look at this next week.
Awesome, thanks!
Pushed a new version just now. Setting useSignificantDigits
to true
will treat precision
as the maximum significant digits to display. Rounding is the default behaviour now, but it's compatible with using trunc
as well.
The
precision
option allows controlling number of figures after the decimal place, but it often makes more sense to control the total number of significant figures. So, for example, setting the number of significant figures to 3 with template's[s]'
would output10.3s
,1.32s
, or0.323s
There's a bit of complication with multiple units, but it seems like the same concept should extend. So
'h[h] m[m] s[s]'
would become12h 30m
,1h 23m
,12m 30s
,1m 23s
,12.3s
,1.23s
,0.123s
or0.0123s
Would also be nice to have a way of specifying that any digits required for padding to the left of the decimal point be populated. So, even if 3 sig figs were requested, instead of getting
12h 30m
you'd get something like12h 34m
, but if no padding is needed, you'd still have1h 23m