January 8 - Accurately Calculating Large Decimals
This coding exercise walks through how to accurately multiple large decimals and examines how a potentially dangerous bug can slip into a codebase.
Guide Tasks
  • Read Tutorial
  • Watch Guide Video
  • Complete the Exercise
Video locked
This video is viewable to users with a Bottega Bootcamp license

Summary

Build a method that accurately multiples two large decimals in Ruby.

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.

Test Cases

Code File