1E18 in Ruby

We will introduce what 1E18 is in Ruby with an example.

1E18 in Ruby

1E18 is a number literal using E-notation. Using E-notation, Ruby interprets the floating-point number with the value 1×10^18 or 1000000000000000000.

We can replace the number 18 in 1E18 with a variable. IE18 is equivalent to the one shown below:

# Ruby
puts 1.0 * 10 ** 18

So we can also write it as shown below:

# Ruby
x = 18
puts 1.0 * 10 ** x

Simply, we can write this as the following:

# Ruby
x = 18
puts 10.0 ** x

1E18 is a literal, considered by the parser, whereas ** is a method call, and the result will be the same.

Write for us
DelftStack articles are written by software geeks like you. If you also would like to contribute to DelftStack by writing paid articles, you can check the write for us page.