3 ways to make big numbers readable in Ruby
Today, I came across the following method in my old code. (This comes from an application supporting calculations in the construction of concrete floors).
def l_factor
((bending_stiffness * 10000000000) / k) ** 0.25
end
This big number looks so unreadable. I started moving the mouse cursor and counting zeros. There are ten of them. I was wondering how I could write it better. And actually, I found 3 ways to make it more readable:
๐ Underscore notation
10_000_000_000
You can format a number with grouped thousands using an underscore delimiter. Ruby lets you insert underscores anywhere inside integers.
๐งฎ Expotential notation
10**10
You would just read it like: \( 10^{10}\)
๐งโ๐ฌ Scientific notation
1e10
This one is my best choice. It actually means: \( 1\cdot10^{10}\) and this notation is commonly used by scientists, mathematicians, and engineers.