21:49
<ljharb>
how come new Intl.NumberFormat('en-US', { style: 'unit', unit: 'byte', unitDisplay: 'narrow', notation: 'compact' }).format(1234567891) prints out 1.2BB and not 1.2GB?
21:59
<Chris de Almeida>
because you said you wanted bytes
22:13
<Chris de Almeida>
whoa, that is weird
22:15
<Chris de Almeida>
100000000 -> 100MB
1000000000 -> 1BB
10000000000 -> 10BB
100000000000 -> 100BB
1000000000000 -> 1TB
22:18
<sffc>
You want new Intl.NumberFormat('en-US', { style: 'unit', unit: 'gigabyte' }).format(1.234567891)
22:18
<Chris de Almeida>
sure, but if you didn't want to have to do your own unit calc for human readable...
22:19
<Chris de Almeida>
it appears every other expression is what one would expect. edit: stops at TB tho
22:19
<sffc>
There's a proposal for unit calculations/preferences but it's blocked on (1) user preferences and (2) lack of consensus that units math belongs in the standard library
22:19
<sffc>
currently at Stage 1 and last presented in 2020 I believe
22:20
<sffc>
The 1BB is because you're printing 1B in compact notation (1K, 1M, 1B, 1T), and then you're attaching a unit to the end
22:22
<Chris de Almeida>
I don't understand why it's not 1G, what am I missing here
22:24
<sffc>
https://www.youtube.com/watch?v=kJQP7kiw5Fk has 8.2B Views
22:28
<Chris de Almeida>
so you're saying : K = thousand M = million B = billion T = trillion and we are just associating M and T with mega and tera erroneously
22:29
<sffc>
Compact decimal notation != SI prefixes
22:30
<Chris de Almeida>
aye
22:30
<Chris de Almeida>
it's the overloading that causes the confusion. thanks
22:30
<sffc>
See https://unicode.org/cldr/charts/43/by_type/numbers.compact_decimal_formatting.html for the symbols different locales use
22:31
<sffc>
I see where the confusion comes from. I wouldn't be opposed to a proposal that uses SI prefixes instead of compact decimal notation when style is "unit"
22:32
<sffc>
If someone files an issue, we can track that better :)
22:33
<Chris de Almeida>
wouldn't that be a breaking change at this point?
22:34
<sffc>
A normative change, sure, but not necessarily web-incompatible; unclear if any of this behavior is required by the spec. I think not.
22:34
<sffc>
A normative change could be a one-liner "the compact decimal suffix can depend on style"
22:40
<sffc>
Yeah actually in practice we already have special patterns for notation: compact with style: currency. So it shouldn't be hard to allow special patterns to be used in that way for style: unit as well.
22:48
<sffc>
https://github.com/tc39/ecma402/issues/810
22:50
<ljharb>
if the unit is "byte" i wouldn't expect anything but megabyte, gigabyte, terabyte, etc
23:02
<Chris de Almeida>
yeah, now that I understand what's happening, it makes perfect sense, but I agree, the number of people who would actually want this behavior in this case is near zero