Your challenge today is to find the original price of a product before sales discount.
For example:
Given an item at $75 sale price after applying a 25% discount, the function should return the original price of that item before applying the sale percentage, which is ($100.00) of course, rounded to two decimal places.
DiscoverOriginalPrice(75, 25) => 100.00M where 75 is the sale price (discounted price), 25 is the sale percentage and 100 is the original price
Note: The return type must be of type decimal and the number must be rounded to two decimal places.
Good luck!
This challenge comes from user ahamidou. Thank you to CodeWars, who has licensed redistribution of this challenge under the 2-Clause BSD License!
Want to propose a challenge for a future post? Email yo+challenge@dev.to with your suggestions!
Top comments (9)
JavaScript
My solution is almost the same as Juan Rodríguez's, just using
.toFixed(2)
. Link to live demo on CodePen.Perl solution with tests:
im not so familier with perl but i like it.
I have figured out the logic in Ruby, but the result gets weird when it comes to perfect numbers.
Which returns
Elixir:
My solution in js
Handles 100% discount 😉
Python
gist.github.com/devparkk/cd1425ba0...