Skip to content

Commit 5900c44

Browse files
[3.6] Add digit separators to Language Tour (#6179)
fixes #6144
1 parent 7aa0104 commit 5900c44

File tree

2 files changed

+34
-2
lines changed

2 files changed

+34
-2
lines changed

examples/misc/lib/language_tour/built_in_types.dart

+11
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,17 @@ void miscDeclAnalyzedButNotTested() {
3737
// #enddocregion const-num
3838
}
3939

40+
// Uncomment when feature is stable:
41+
// {
42+
// // #docregion digit-separators
43+
// var n1 = 1_000_000;
44+
// var n2 = 0.000_000_000_01;
45+
// var n3 = 0x00_14_22_01_23_45; // MAC address
46+
// var n4 = 555_123_4567; // US Phone number
47+
// var n5 = 100__000_000__000_000; // one hundred million million!
48+
// // #enddocregion digit-separators
49+
// }
50+
4051
{
4152
// #docregion quoting
4253
var s1 = 'Single quotes work well for string literals.';

src/content/language/built-in-types.md

+23-2
Original file line numberDiff line numberDiff line change
@@ -159,7 +159,7 @@ assert((3 & 4) == 0); // 0011 & 0100 == 0000
159159
For more examples, see the
160160
[bitwise and shift operator][] section.
161161

162-
Literal numbers are compile-time constants.
162+
Number literals are compile-time constants.
163163
Many arithmetic expressions are also compile-time constants,
164164
as long as their operands are
165165
compile-time constants that evaluate to numbers.
@@ -173,6 +173,26 @@ const msUntilRetry = secondsUntilRetry * msPerSecond;
173173

174174
For more information, see [Numbers in Dart][dart-numbers].
175175

176+
You can use one or more underscores (`_`) as digit separators
177+
to make long number literals more readable.
178+
Multiple digit separators allow for higher level grouping.
179+
180+
{% comment %}
181+
Attach code excerpt misc/lib/language_tour/built_in_types.dart (digit-separators)
182+
when feature is stable:
183+
{% endcomment %}
184+
185+
```dart
186+
var n1 = 1_000_000;
187+
var n2 = 0.000_000_000_01;
188+
var n3 = 0x00_14_22_01_23_45; // MAC address
189+
var n4 = 555_123_4567; // US Phone number
190+
var n5 = 100__000_000__000_000; // one hundred million million!
191+
```
192+
193+
:::version-note
194+
Using digit separators requires a [language version][] of at least 3.6.0.
195+
:::
176196

177197
## Strings
178198

@@ -254,7 +274,7 @@ var s = r'In a raw string, not even \n gets special treatment.';
254274
See [Runes and grapheme clusters](#runes-and-grapheme-clusters) for details on how
255275
to express Unicode characters in a string.
256276

257-
Literal strings are compile-time constants,
277+
String literals are compile-time constants,
258278
as long as any interpolated expression is a compile-time constant
259279
that evaluates to null or a numeric, string, or boolean value.
260280

@@ -415,3 +435,4 @@ Symbol literals are compile-time constants.
415435
[characters API]: {{site.pub-api}}/characters
416436
[characters example]: {{site.pub-pkg}}/characters/example
417437
[`Symbol`]: {{site.dart-api}}/{{site.sdkInfo.channel}}/dart-core/Symbol-class.html
438+
[language version]: /guides/language/evolution#language-versioning

0 commit comments

Comments
 (0)