File: examples.php

Recommend this page to a friend!
  Classes of Alejandro Bazan  >  PHP Order of Magnitude Prefix  >  examples.php  >  Download  
File: examples.php
Role: Example script
Content type: text/plain
Description: Examples
Class: PHP Order of Magnitude Prefix
Get the name of the prefix for a measure value
Author: By
Last change:
Date: 10 days ago
Size: 1,631 bytes
 

Contents

Class file image Download
<?php
require_once "magnitudePrefix.class.php";

$mp = new MagnitudePrefix();

//Some numbers
echo"<br>Some Numbers<br>";
$number = 0.2;
echo
$number . " => " . $mp->getPrefixed($number, 'seconds') . "<BR/>";

$number = 0.002;
echo
$number . " => " . $mp->getPrefixed($number, 'grams') . "<BR/>";

$number = 200;
echo
$number . " => " . $mp->getPrefixed($number, 'Volts') . "<BR/>";

$number = 200000;
echo
$number . " => " . $mp->getPrefixed($number, 'Ohms') . "<BR/>";

$number = 0.00002;
echo
$number . " => " . $mp->getPrefixed($number, 'Farads') . "<BR/>";

//An expression, result from random calculation
echo"<br>An expression, result from random calculation<br>";
$number = round(rand() * exp(rand(-23,23)),2);
echo
$number . " => " . $mp->getPrefixed($number, 'meters') . "<BR/>";

//Expand scale
echo"<br>Expand scale<br>";
$mp->setScaleToExpandedStandard();
$number = 0.25;
echo
$number . " => " . $mp->getPrefixed($number, 'meters') . "<BR/>";

//Use Years
echo"<br>Use Years<br>";
$mp->setScaleToYears();
$number = 250;
echo
$number . " => " . $mp->getPrefixed($number, '') . "<BR/>";

//Custom scale
echo"<br>Custom scale<br>";
$mp->setScaleToCustom(array(
            array(
'factor'=>1E-3, 'prefix'=>'mili'),
            array(
'factor'=>1E-2, 'prefix'=>'centi'),
            array(
'factor'=>1, 'prefix'=>''),
            array(
'factor'=>1E3, 'prefix'=>'Kilo')
        )
);
$number = 250;
echo
$number . " => " . $mp->getPrefixed($number, 'meters') . "<BR/>";
$number = 0.43;
echo
$number . " => " . $mp->getPrefixed($number, 'meters') . "<BR/>";
$number = 0.005;
echo
$number . " => " . $mp->getPrefixed($number, 'meters') . "<BR/>";

?>


For more information send a message to info at phpclasses dot org.