Published in: PHP
|
|
|
URL: http://reusablecode.blogspot.com/search/label/roman%20numerals
A library of functions for converting between Arabic and Roman numerals.
Expand |
Embed | Plain Text
<?php /* PHP Roman Numeral Library Copyright (c) 2008, reusablecode.blogspot.com; some rights reserved. This work is licensed under the Creative Commons Attribution License. To view a copy of this license, visit http://creativecommons.org/licenses/by/3.0/ or send a letter to Creative Commons, 559 Nathan Abbott Way, Stanford, California 94305, USA. */ // Convert Arabic numerals into Roman numerals. function roman($arabic) { $fractions = Array("", "•", "••", "•••", "••••", "•••••", "S", "S•", "S••", "S•••", "S••••", "S•••••", "I"); if ($arabic > 4999) { // For large numbers (five thousand and above), a bar is placed above a base numeral to indicate multiplication by 1000. // Since it is not possible to illustrate this in plain ASCII, this function will refuse to convert numbers above 4999. } elseif ($arabic == 0) { // About 725, Bede or one of his colleagues used the letter N, the initial of nullae, // in a table of epacts, all written in Roman numerals, to indicate zero. return "N"; } else { // Handle fractions that will round up to 1. { } // With special cases out of the way, we can proceed. // NOTE: modulous operator (%) only supports integers, so fmod() had to be used instead to support floating point. // Handling for fractions. if ($arabic > 0) { } return $roman; } } // Expand subtractive notation in Roman numerals. function roman_expand($roman) { return $roman; } // Compress Roman numerals using subtractive notation. function roman_compress($roman) { return $roman; } // Convert Roman numerals into Arabic numerals. function arabic($roman) { $result = 0; // Remove subtractive notation. $roman = roman_expand($roman); // Calculate for each numeral. return $result; } ?>
You need to login to post a comment.

