Calculating value from percent
Posted on August 31, 2008, Filled under PHP,
Bookmark it
This short tutorial is aimed to help you how to calculate the percent value from a total. Let’s suppose you have a e-commerce site and you offer discounts to the customers. You need to show them how much is the discount value worthing.
Here’s a sample from an order total:
Our special discount: 30% (-$390)
Final price: $910
Here’s the script which calculates the special discount value and the final price:
<?php $percent = '30'; // without % $total = '1300'; // initial value /* Calculate $percent% from $total */ $discount_value = ($total / 100) * $percent; $final_price = $total - $discount_value; // Format numbers with number_format() $total = number_format($total); $discount_value = number_format($discount_value); $final_price = number_format($final_price); echo "Notebook's price: $".$total."<br />Our special discount: <strong>". $percent."%</strong> (-$".$discount_value.")<br />Final price: $".$final_price; ?>
Any comments and suggestions regarding this script are welcomed.
Do you wish to receive the latest updates as soon as they are posted? Get our RSS Feed or Subscribe to the Newsletter!
- August 31, 2008
- article by Gabriel C.
- 1 comment
Sponsors
Related Posts
-
Calculate percent from valueat August 31, 2008
-
How to Create a PHP Word Popularity Scriptat November 7, 2008 with 4 comments
-
PHP: Calculate the Size, Number of Files & Folders of a Directoryat September 24, 2008 with 3 comments

One Reply to "Calculating value from percent"
September 18, 2008 at 11:11 AM
Esse script é simples e direto.
Muito Bom!
tags
calculo de porcentagem com php exemplo script