Last Updated: February 25, 2016
·
1.109K
· muszynskis

Ruby: How to Increase Long Integers Readability?

Introduction

Let's compare two notations of some long number. Which of them is easier to read?

1: 100000000000
2: 100,000,000,000

I guess you would choose second one, am I right?

Problem

Ruby does not let you write any comma inside of long integer.

> 100,000,000,000
=> SyntaxError: syntax error, unexpected ',', expecting $end

Solution

Use underscore instead of comma!

> 100_000_000_000
=> 100000000000

It is pretty simple and works great :)

Recommend
Say Thanks
Update Notifications Off
Respond