Q:

Why isn't my BigDecimal calculator outputting the correct value?

I programmed a calculator:
require 'bigdecimal'

def addition()
  print "Enter the first number "
  number1 = BigDecimal(gets.chomp)
  print "Enter the second number  "
  number2 = BigDecimal(gets.chomp)
  sum = number1 + number2
  print sum
end

It is not giving the correct sum. If I enter 4.21 as number one and 2.11 for number two, I get 0.632E1. If I enter 4.21 as number one and 2.11 for number two, I get 0.632E1.
Please help.

A:

That sum is correct. 0.632E1 is notation for 6.32.
To get a more "normal" looking number:
# BigDecimal built-in conversion to String
sum.to_s('F')

As shown in the BigDecimal documentation for .to_s
You could also use:
# Converts to Float, you would lose precision for display, but at least you get
# the normal expected behaviour of a Float
sum.to_f  

# Converts to String with known precision (technically this just goes via Float)
sprintf( '%.4f', sum ) 

