Skip to content

Commit

Permalink
Create dart-digit-separators.md
Browse files Browse the repository at this point in the history
  • Loading branch information
petermekhaeil authored Dec 29, 2024
1 parent 09cc774 commit 85d2173
Showing 1 changed file with 17 additions and 0 deletions.
17 changes: 17 additions & 0 deletions learnings/dart-digit-separators.md
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
# Dart Supports Underscore Digit Separators

In Dart (starting from version 3.6.0), you can use underscores (`_`) as digit separators in number literals to make them more readable. This is especially handy for large numbers or when grouping digits for higher-level clarity.

Here are some examples:

```dart
var n1 = 1_000_000;
var n2 = 0.000_000_000_01;
var n3 = 0x00_14_22_01_23_45; // MAC address
var n4 = 65_1234_5678; // SG Phone number
var n5 = 100__000_000__000_000; // one hundred million million!
```

This feature makes it easier to read long numeric values and organize digits meaningfully.

Dart isn’t alone in supporting this - other languages like JavaScript, Java, Python, and Kotlin also allow underscore digit separators. It's a great example of a feature that crosses language boundaries to make code cleaner and more human-readable.

0 comments on commit 85d2173

Please sign in to comment.