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 :)
Written by Sebastian Muszyński
Related protips
Have a fresh tip? Share with Coderwall community!
Post
Post a tip
Best
#Ruby
Authors
Sponsored by #native_company# — Learn More
#native_title#
#native_desc#