Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Separating digits for large numbers in C# code

Tags:

In C++ you can separate the digits for readability in your code with apostrophes:

int num = 1'000'000; 

In Ruby, you can use underscores:

num = 1_000_000 

Is there a similar syntax for C#? I tried a few different searches but only came up with results for outputting or reading numbers in a particular format.

like image 948
Shaun Avatar asked Jul 05 '16 18:07

Shaun


People also ask

How do you separate digits from integers?

toCharArray() to Get the Array of Characters. Another way of separating the digits from an int number is using the toCharArray() method. We will convert the integer number into a string and then use the string's toCharArray() to get the characters' array. Now we can print out all the characters one by one.

How do you extract digits from a number?

Extracting digits of a number is very simple. When you divide a number by 10, the remainder is the digit in the unit's place. You got your digit, now if you perform integer division on the number by 10, it will truncate the number by removing the digit you just extracted.


1 Answers

As of the time this answer is written, that feature does not exist in C#. However, there is a feature request for it, and it looks like it will be part of C# 7, which is the upcoming version.

The feature request is listed on their C# 7 list of features, but you probably shouldn't assume 100% it will make it in. Things are subject to change.

like image 148
mason Avatar answered Sep 21 '22 00:09

mason