loading...

Discussion on: Daily Challenge #30 - What is the price?

Collapse
scrabill profile image
Shannon Crabill

I have figured out the logic in Ruby, but the result gets weird when it comes to perfect numbers.

def DiscoverOriginalPrice(sale_price, discount)
  sale_percent = sale_price / (100.00 - discount)
  original_price = sale_percent * 100.00
  original_price.round(2)
end

Which returns

DiscoverOriginalPrice(75,25) => 100.0 # Close, but it should be 100.00
DiscoverOriginalPrice(51.98,30) => 74.26 
DiscoverOriginalPrice(50,50) => 100.0 # Close, but it should be 100.00