Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Is there a readable way to put millions into c# code?

This is a little hard to read:

int x = 100000000;

Is there an easy way to write:

int x = 100,000,000;

So that the scale is obvious?

Please note this is NOT about formatting the output.

like image 802
ManInMoon Avatar asked Jun 05 '15 17:06

ManInMoon


Video Answer


1 Answers

Starting with C#7 you will be able to use the underscore-char (_) to seperate digit groups. The underscore can be placed anywhere in a number. A simple example:

const int MILLION = 1_000_000;

You can place the _ anywhere you want and can even combine it with integer literals:

const int USHORT_MAX = 0xFF_FF;

Or even with floats and decimals, even after the decimal sign:

const decimal SMALL_VALUE = 0.000_000_001;
like image 98
crazy_crank Avatar answered Nov 03 '22 13:11

crazy_crank