Skip to content

Use Numeric Separators to Easily Read Big Numbers

numeric separators js php cpp python java c#

Sometimes, it becomes difficult to read numbers that contain many digits.

For example, 1000 is readable but what about 1000000?

Yeap, it becomes pretty tricky to read.

In real life, we add commas ( , ) or punctuation ( . ) depending on where you live.

But because this is a number and not a string, we can’t add commas or dots as thousands indicators.

 

However, many modern languages give us the numeric separator which is an underscore ( _ ) placed between characters in a number to make it easier to read.

Here’s an example in JavaScript:

 

 

In the above example, there are a few use cases when you’d want to use the numeric separator to make numeric notations more readable.


 

 

The numeric separator is also available starting with Python 3.6, Java SE 7, and C# 7.

In C++ this feature is called digit separator and it has been available starting with version 14.

Note that it is using simple quotation mark (  ) instead of ( _ ) underscore.

 

 

Happy coding 😊

 


Let me know what you think about this article in the comments section below.

If you find this article helpful, please share it with others and subscribe to the blog to support me, and receive a bi-monthly-ish e-mail notification on my latest articles.   
  

Comments

Tags: