Digit Separator (Also Known as Numeric Separator)
Digit Separator does NOT change the variable value. Its only a visual separator for digit grouping purposes.
This is a common feature of modern languages, and can aid readability of long literals, or literals whose value should clearly separate into parts.
- C
- C++
- C#
- Java
- Rust
- Go
- Javascript
- Typescript
- Python
// Not Available
// Since C++14
// You can use Simple Quotation Mark ( ' ) as a digit separator.
// Uniform Initialization (since C++11)
// Also known as Brace Initialization or List Initialization
int decimal {1'000'000'000};
int hexadecimal {0xFFFF'FFFF};
int octal {00'23'00};
int binary {0b1010'0011};
More Info:
// Since C# 7.0
// You can use Underscore ( _ ) as a Digit separator.
int variableName = 1_000_000;
long variableName = 9_223_372_036_854_775_807L;
double variableName = 10_000.50;
decimal variableName = 10_000.50m;
int binary = 0b_1010_1010;
int hexadecimal = 0xFF_FF_FF;
// Since Java 7
// You can use Underscore ( _ ) as a Digit separator.
// Example from Official Docs
long creditCardNumber = 1234_5678_9012_3456L;
long socialSecurityNumber = 999_99_9999L;
float pi = 3.14_15F;
long hexBytes = 0xFF_EC_DE_5E;
long hexWords = 0xCAFE_BABE;
long maxLong = 0x7fff_ffff_ffff_ffffL;
byte nybbles = 0b0010_0101;
long bytes = 0b11010010_01101001_10010100_10010010;
More Info:
// You can use Underscore ( _ ) as a Digit separator.
let variable_name = 1_000_000;
let variable_name = 9_223_372_036_854_775_807_i64;
let variable_name = 10_000.50_f64;
let binary = 0b1010_1010;
let hexadecimal = 0xFF_FF_FF;
// Since Go 1.13
// You can use Underscore ( _ ) as a Digit separator.
variableName := 1_000_000
variableName := 10_000.50
binary := 0b1010_1010
octal := 0o755
hexadecimal := 0xFF_FF_FF
// Support:
// Node 12.5.0+
// Firefox 70+
// Safari 13+
// Chrome 75+
// You can use Underscore ( _ ) as a numeric separator.
const decimal = 1_000_000_000_000; // grouped per thousand
const decimal = 1_000_000.220_720; // grouped per thousand
const binary = 0b01010110_00111000; // grouped per octet
const binary = 0b0101_0110_0011_1000; // grouped per nibble
const hexadecimal = 0x40_76_38_6A_73; // grouped per byte
const bigInt = 4_642_473_943_484_686_707n; // grouped per thousand
const octal = 0o123_456;
More Info:
// Since TypeScript 2.7
// You can use Underscore ( _ ) as a numeric separator.
const decimal = 1_000_000_000_000; // grouped per thousand
const decimal = 1_000_000.220_720; // grouped per thousand
const binary = 0b01010110_00111000; // grouped per octet
const binary = 0b0101_0110_0011_1000; // grouped per nibble
const hexadecimal = 0x40_76_38_6A_73; // grouped per byte
const bigInt = 4_642_473_943_484_686_707n; // grouped per thousand
const octal = 0o123_456;
More Info:
# Since PEP-515 (Python 3.6)
# You can use Underscore ( _ ) as a digit separator.
decimal = 1_000_000_000
hexadecimal = 0xFFFF_FFFF
octal = 0o257
binary = 0b1010_0011