Ruby Coding Exercise: Accurately Calculating Large Decimals

0
623

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

Code 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.

LEAVE A REPLY

Please enter your comment!
Please enter your name here