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', 50, true);
$priceRounder->addRule('>', 50, '<=', 99, 'next_int', 0, true);

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

$priceRounder->setPrice(5.6);

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

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

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

$priceRounder->setPrice(5.02);

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

$priceRounder->removeAllRules();

$priceRounder->addRule('>', 0, '<', 50, 'make_equal', 50, true, 5, 10);

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

$priceRounder->setPrice(3.25);

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