Become PHP Expert in 30 days
FreeMarriage.com - Free Online Matrimonial
FlashWebHost.com - Professional Web Hosting, Designing.
DAY 2 PHP PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_6.php
Code:<?php $computerPrice = '20000' ; $printerPrice = '5000' ; $discount = 0.1; // 10% discount. echo ' Total cost = Rs: ' . ($computerPrice+$printerPrice) . ' /- ' ; echo '<br>' ; echo ' Price after discount = Rs: ' . ( ($computerPrice + $printerPrice) - (($computerPrice + $printerPrice) * $discount)) . '/-' ;
DAY 2 PHP PROGRAMMING
http://php.flashwebhost.com/tom/day_2_variables_7.php
Code:<?php $computerPrice = 20000 ; $printerPrice = 5000 ; $discount = 0.2 ; // 20% discount. $totalCost = $computerPrice + $printerPrice ; echo ' Total cost = Rs: ' . $totalCost . '/-' ; echo '<br>' ; echo ' Price after discount = Rs. ' . ($totalCost - ($totalCost * $discount )) . '/-' ;
I just tried with $discount = 0.1 , $discount = 0.2.
But when i add $discount = 12 , the result was wrong.
So i searched in google for "percentage formula in php" and i got the following
See the result at http://php.flashwebhost.com/sibichan...ariables_7.phpPHP Code:<?php$shirt_price = 300;$pant_price = 300;$discount = 12;$total_cost = ($shirt_price+$pant_price);
echo 'Total price is Rs : ' . $total_cost . '/-';
echo '<br>';
echo ' Price after discount is Rs : ' . ($total_cost - ($total_cost*$discount / 100)). '/-';
Last edited by Vahaa11; 05-10-2014 at 05:46 AM.
DAY 2 PROGRAMMING:
http://php.flashwebhost.com/vineesh/...ariables_6.php
Seems it worked :). My code is:
Code:<?php $costOfApple = 50; $costOfOrange = 30; $discount = 0.5; // 50% discount. echo 'Cost of an apple = ' . $costOfApple . '<br>' . 'Cost of Orange = ' . $costOfOrange . '<br>'; echo 'Cost of apple + Orange = ' . ($costOfApple + $costOfOrange) . '<br>'; echo 'Discount ' . $discount . '<br>' ; echo 'Cost after discount = ' . ( ($costOfApple + $costOfOrange) - (($costOfApple + $costOfOrange) * $discount ) ) . '/-';
DAY 2 PROGRAMMING .
http://php.flashwebhost.com/vineesh/...ariables_7.php
Code
Code:<?php $costOfApple = 100; $costOfOrange = 70; $totalCost = $costOfApple + $costOfOrange; $discount = 0.2; echo 'Cost of Apple = Rs. ' . $costOfApple . ' /- <br>'; echo 'Cost of Orange = Rs. ' . $costOfOrange . '/- <br>'; echo 'Total Cost = Rs. ' . $totalCost . '/- <br>'; echo 'Discount = Rs. ' . $totalCost * $discount . '/- <br>' ; echo 'Cost after discount = Rs. ' . ( ( $totalCost ) - ( ($totalCost) * $discount )) . '/- <br>';
Bookmarks