Skip to content
Discussion options

You must be logged in to vote

Your formula is correct. Convert 18% to decimal form by dividing by 100:

18% = 0.18

Then calculate the discount:

$124.95 × 0.18 = $22.491

Subtract that from the original price:

$124.95 − $22.491 = $102.459

or another option you can do is just do (1 - discount) * original price to get the final price.

Since currency is normally displayed to two decimal places, round the final result to $102.46. The discount amount would display as $22.49.

It is best not to round intermediate values. Keep the full precision during the calculation, then round the final monetary result to two decimal places. A one-cent difference can happen when a calculator rounds the discount before subtracting it or uses a…

Replies: 1 comment

Comment options

You must be logged in to vote
0 replies
Answer selected by johnTurne
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
Discussions GitHub Discussions is a collaborative communication feature Question Ask and answer questions about GitHub features and usage Welcome 🎉 Used to greet and highlight first-time discussion participants. Welcome to the community! source:ui Discussions created via Community GitHub templates
2 participants