Created
November 10, 2017 17:23
-
-
Save boykoc/2187fbeb36c873bf42181c067d52e187 to your computer and use it in GitHub Desktop.
Method to *evenly* split a bill among people.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
## | |
# Module to split bills evenly for a group of people (i.e. splitting cost for a pizza lunch). | |
# | |
# Basic use: | |
# `BillSplitter.split_bill(total: 82.42, people: 11)` => "Each person should fork over 7.49!" | |
module BillSplitter | |
require 'bigdecimal' | |
def self.split_bill(total: 0.00, people: 1) | |
bd_total = BigDecimal.new(total.to_s) | |
bd_people = BigDecimal.new(people.to_s) | |
cost = bd_total / bd_people | |
"Each person should fork over #{cost.truncate(2).to_s('F')}!" | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment