Assists for adding and maybe removing digit separators from number literals #56467
Labels
devexp-assist
Issues with analysis server assists
legacy-area-analyzer
Use area-devexp instead.
P2
A bug or feature request we're likely to work on
type-enhancement
A request for a change that isn't a bug
As part of #56188, we want to add one or more assists for adding, and maybe removing digit separators (
_
) from number literals. Here are the cases I've thought of:Decimal integer literal
Given a decimal integer literal,
var x = /*caret*/1000000;
, offer to add a separator at 3 digits, yieldingvar x = 1_000_000;
.If we only offer "every 3 digits" for a decimal integer, then we cannot add any separator for a number with 1, 2, or 3 digits. But what about 4? The Internet has many opinions about whether digit separators should be used for a 4-digit integer. Wikipedia has a good section on Digit grouping. According to a guide from the International Bureau of Weights and Measures, a 4-digit number can feature a separator, but "this practice is not usually followed for numbers having only four digits on either side of the decimal marker except when uniformity in a table is desired." 🤷
I would be ok if we started offering the separators at 4 digits, or at 5 digits.
Hexadecimal integer literal
Given a hexadecimal integer literal,
var x = /*caret*/0xff33cc;
, offer to add a separator at every 2 digits, yieldingvar x = 0xff_33_cc;
.Wikipedia mentions that separating every 2 digits, equivalent to each byte, is standard: "Similarly, in hexadecimal (base-16), full spaces are usually used to group digits into twos, making each group correspond to a byte."
Decimal double literal
Given a decimal double literal,
var x = /*caret*/12345.67890;
, offer to add a separator at 3 digits, both to the left of the decimal, and to the right, yieldingvar x = 12_345.678_90;
.The same Wikipedia entry, and other areas of the Internet, indicate that commas are not standard on the fractional side of the decimal point, but that other separators like a "thin space", are standard.
Scientific notation double literal
Given a scientific notation double literal,
var x = /*caret*/123123.456456e789789;
, offer to add a separator at 3 digits, to the left of the decimal, the right of the decimal, and the right of thee
, yieldingvar x = 123_123.456_456e789_789;
.I cannot find any examples or advice regarding separators in the exponent; it seems without evidence to the contrary, we should just be consistent and offer the separators.
Existing separators
When a number has existing separators, I think we should still offer to "add digit separators" to "correct" any "incorrect" ones. It could be worded something like "place digit separator every 3 digits." We could also not offer the assist when the separators are in the expected positions.
Removing separators
It seems to make sense to offer to remove separators. It makes a nice pair of opposing assists. I can also see wanting to remove separators in bulk. Although I think assists cannot currently be offered in bulk.
The text was updated successfully, but these errors were encountered: