This coding exercise walks through how to accurately multiple large decimals and examines how a potentially dangerous bug can slip into a codebase.
Summary
Build a method that accurately multiples two large decimals in Ruby.
Exercise File
Exercise Description
Given the following decimals:
10.0987345897234093284023 42.0987345897234093284023
Build a method that accurately multiples the values.
Sample Output
"425.14394718482513504388005529072886672947064529"
Real World Usage
This is a tricky Ruby coding interview question because the problem looks incredibly simple. However, in order to work with large decimals in Ruby, you’ll discover that you need to implement a number of mechanisms in order to accurately generate the correct answer. Additionally, accurately calculating decimal values is vital in a wide variety of applications, especially financial and scientific programs.
Solution
Can be found on the solutions branch on github.