turnilo
turnilo copied to clipboard
Custom formatter for mesasures in Bits
Hello and thanks for this grandiose project!
We would be happy to have a formatter that writes "b" (lowercase B, signifying "bits") instead of "B" (uppercase B, signifying "bytes") following the relevant SI prefix (Ki/Mi/Gi).
Having bit based units displayed as B is actually quite irritating. At the moment we're calculating everything as Megabits and display that as a plain number but it's hard to read (739273 Megabits) and having SI prefixes for bits would be nicer.
Is this possible with plain numbro.js? The v1 docs only talk about Bytes.
I can't format that way with either version of numbro.js. Sadly, I don't think we can do anything about it - I don't see any other library that handles your case (which sounds simple!).
Thanks for the feedback. I went searching upstream at the numbro.js repo.
Would it be possible to utilize this feature (Byte symbol localization) for replacing B with b (yes it would def be hacky)? https://github.com/BenjaminVanRyseghem/numbro/issues/359
But wouldn't you need to multiply your input by 8?
input: 16
formatter: 2B
custom symbol: 2b
But you wan't to get 16b
.
Anyways, we had some plans for better formatters (#504) and I would like to leave this issue for future considerations. Maybe we will be able to handle this case.
Great, thanks for taking this case into consideration.
If calculation is needed to scale the values appropriately, this can be achieved by adding a custom measure with a corresponding formula. In our case the numbers that are shown in the UI are actually "in bits". Formatting them with the numbro bytes formatter does not change the actual value but only attach the suffix SI-Unit + B
. So just replacing B with b (like the locale patch linked above does) would suffice.
I think I'd reword this to be about "add support for unit prefixes".
SI (multiples of 1000) would be a good start: for example for a unit of "bps" (cf. #634) it would be good to think in terms of "Mbps", "Gbps" etc, rather than "million bps", "billion bps" etc. For a unit of "bytes", then it gets a bit more complicated, as IEC prefixes (base 2) are more commonly used, so "MiB" = 1,048,576 bytes etc.
For bytes, it seems like numbro.js offers that support with e.g. format: "0,0.00 b". Anything else is going to be more difficult I think, cf. https://github.com/BenjaminVanRyseghem/numbro/issues/126 for a 2015-era task to add SI support to Numbro.