PHP Classes

Numeral: Convert numbers between Roman and Hindu formats

Recommend this page to a friend!
     
  Info   Example   View files Files   Install with Composer Install with Composer   Download Download   Reputation   Support forum   Blog    
Ratings Unique User Downloads Download Rankings
Not enough user ratingsTotal: 122 All time: 9,486 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

 

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 (2)  
File Role Description
Plain text file class.numeral.php Class Main class file
Accessible without login Plain text file example.php Example Example script

The PHP Classes site has supported package installation using the Composer tool since 2013, as you may verify by reading this instructions page.
Install with Composer Install with Composer
 Version Control Unique User Downloads Download Rankings  
 0%
Total:122
This week:0
All time:9,486
This week:206Up