PHP Classes

Numeral: Convert numbers between Roman and Hindu formats

Recommend this page to a friend!
  Info   View files Example   View files View files (2)   DownloadInstall with Composer Download .zip   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 122 All time: 9,473 This week: 206Up
Version License PHP version Categories
numeral 1.0GNU General Publi...5.2PHP 5, Text processing, Math
Description 

Author

This class can be used to convert numbers between Roman or Hindu formats.

It takes an integer number and converts it to Roman format.

The class can also do the opposite, i.e. convert Roman numeral and convert it back to an integer.

Picture of Gordon Pettey
Name: Gordon Pettey <contact>
Classes: 1 package by
Country: United States United States
Age: 36
All time rank: 4353550 in United States United States
Week rank: 307 Up35 in United States United States Up

Example

<?php

require_once('./class.numeral.php');

$num = new numeral(); // Numeral object.
$value = array(); // Array of values to test with.
$value[] = 2008;
$value[] = "1997";
$value[] = "MCCCXXXVII";
$value[] = 5000;
$value[] = "MCMLXXXVII";
$value[] = "1987";
$value[] = 60000;
$value[] = 500000;
$value[] = 16777216;
$value[] = "_M_M_M_M_M_M_M_M_M_M_M_M_M_M_M_M_D_C_C_L_X_X_VMMCCXVI";
// Underscore used in place of "overbar"

foreach($value as $var) { // Loop through test values using numeral
 
$num->setValue($var); // object with preset value.
 
echo $num->getValue()." - ";
 echo
$num->getType()." - ";
 echo
$num->getHindu()." - ";
 echo
$num->getRoman()." - ";
 echo
$num->convert()."<br />";
 echo
"<br />";
}

echo
"<br /><br /><br />";

$num2 = new numeral(); // Create a second numeral object.
foreach($value as $var) { // This time, loop through while setting the
 
echo $num2->getValue($var)." - "; // value as a parameter of each method.
 
echo $num2->getType($var)." - ";
 echo
$num2->getHindu($var)." - ";
 echo
$num2->getRoman($var)." - ";
 echo
$num2->convert($var)."<br />";
 echo
"<br />";
}

?>


  Files folder image Files  
File Role Description
Plain text file class.numeral.php Class Main class file
Accessible without login Plain text file example.php Example Example script

 Version Control Unique User Downloads Download Rankings  
 0%
Total:122
This week:0
All time:9,473
This week:206Up