Login   Register  
PHP Classes
elePHPant
Icontem

File: example.php

Recommend this page to a friend!
Stumble It! Stumble It! Bookmark in del.icio.us Bookmark in del.icio.us
  Classes of Ovunc Tukenmez  >  PHP Price Rounder Calculator  >  example.php  >  Download  
File: example.php
Role: Example script
Content type: text/plain
Description: example
Class: PHP Price Rounder Calculator
Round price amounts according to certain rules
Author: By
Last change:
Date: 1 year ago
Size: 1,475 bytes
 

Contents

Class file image Download
<?php
require_once('class/PriceRounder.php');

$priceRounder = new PriceRounder();
$priceRounder->setPrice(5.23);

$priceRounder->addRule('>'0'<'50'make_equal'50true);
$priceRounder->addRule('>'50'<='99'next_int'0true);

echo 
$priceRounder->getFinalPrice() . "<br />";

$priceRounder->setPrice(5.6);

echo 
$priceRounder->getFinalPrice() . "<br />";

$priceRounder->removeAllRules();
$priceRounder->addRule('>'0'<'10'make_equal'10true);
$priceRounder->addRule('>'10'<'20'make_equal'20true);
$priceRounder->addRule('>'20'<'30'make_equal'30true);
$priceRounder->addRule('>'30'<'40'make_equal'40true);
$priceRounder->addRule('>'40'<'50'make_equal'50true);
$priceRounder->addRule('>'50'<'60'make_equal'60true);
$priceRounder->addRule('>'60'<'70'make_equal'70true);
$priceRounder->addRule('>'70'<'80'make_equal'80true);
$priceRounder->addRule('>'80'<'90'make_equal'90true);
$priceRounder->addRule('>'90'<='99'next_int'0true);

echo 
$priceRounder->getFinalPrice() . "<br />";

$priceRounder->setPrice(5.02);

echo 
$priceRounder->getFinalPrice() . "<br />";

$priceRounder->removeAllRules();

$priceRounder->addRule('>'0'<'50'make_equal'50true510);

echo 
$priceRounder->getFinalPrice() . "<br />";

$priceRounder->setPrice(3.25);

echo 
$priceRounder->getFinalPrice() . "<br />";
?>