csharplang/proposals/csharp-7.0/digit-separators.md
Bill Wagner 8b7d2d5410 markdown lint changes to C# 7.0 proposals
These changes are to improve the experience for publishing these proposals.

One change should be carefully reviewed to ensure I didn't introduce any technical errors:
I translated the binary literals grammar into ANTLR to match all other specs and proposals.  See changes in proposals/csharp-7.0/binary-literals.md

Other changes are:
1. Use  consistent ATX headers, with one H1 per proposal.
1. use `csharp` as language identifier in code snippets
1. Use relative links to other markdown from the dotnet/csharplang repo. That way, when published on docs.microsoft.com, the links will resolve to the publsihed articles on the same site. (Links to content not being published are not modified.)
1. spelling / capitalization found by the lint tool.
2019-03-07 11:39:58 -05:00

1.3 KiB

Digit separators

Being able to group digits in large numeric literals would have great readability impact and no significant downside.

Adding binary literals (#215) would increase the likelihood of numeric literals being long, so the two features enhance each other.

We would follow Java and others, and use an underscore _ as a digit separator. It would be able to occur everywhere in a numeric literal (except as the first and last character), since different groupings may make sense in different scenarios and especially for different numeric bases:

int bin = 0b1001_1010_0001_0100;
int hex = 0x1b_a0_44_fe;
int dec = 33_554_432;
int weird = 1_2__3___4____5_____6______7_______8________9;
double real = 1_000.111_1e-1_000;

Any sequence of digits may be separated by underscores, possibly more than one underscore between two consecutive digits. They are allowed in decimals as well as exponents, but following the previous rule, they may not appear next to the decimal (10_.0), next to the exponent character (1.1e_1), or next to the type specifier (10_f). When used in binary and hexadecimal literals, they may not appear immediately following the 0x or 0b.

The syntax is straightforward, and the separators have no semantic impact - they are simply ignored.

This has broad value and is easy to implement.