<?xml version="1.0" encoding="UTF-8"?>
<rss version="2.0"
	xmlns:content="http://purl.org/rss/1.0/modules/content/"
	xmlns:wfw="http://wellformedweb.org/CommentAPI/"
	xmlns:dc="http://purl.org/dc/elements/1.1/"
	xmlns:atom="http://www.w3.org/2005/Atom"
	xmlns:sy="http://purl.org/rss/1.0/modules/syndication/"
	xmlns:slash="http://purl.org/rss/1.0/modules/slash/"
	>

<channel>
	<title>PHP Software Developing &#187; Numbers</title>
	<atom:link href="http://www.phpdeveloping.co.za/category/numbers/feed" rel="self" type="application/rss+xml" />
	<link>http://www.phpdeveloping.co.za</link>
	<description>for the love of PHP Development</description>
	<lastBuildDate>Tue, 29 Sep 2009 15:38:14 +0000</lastBuildDate>
	<generator>http://wordpress.org/?v=2.8.2</generator>
	<language>en</language>
	<sy:updatePeriod>hourly</sy:updatePeriod>
	<sy:updateFrequency>1</sy:updateFrequency>
			<item>
		<title>Decimal to Roman numbers</title>
		<link>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html</link>
		<comments>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html#comments</comments>
		<pubDate>Wed, 05 Aug 2009 07:37:21 +0000</pubDate>
		<dc:creator>chris</dc:creator>
				<category><![CDATA[Numbers]]></category>
		<category><![CDATA[roman numbers]]></category>

		<guid isPermaLink="false">http://www.phpdeveloping.co.za/?p=121</guid>
		<description><![CDATA[I needed a function to translate from decimal numbers to their Roman number equivalent.  Here&#8217;s a handy little function I found.

private function numberToRoman&#40;$num&#41;
&#123;
     $n = intval&#40;$num&#41;;
     $result = '';
&#160;
     $lookup = array&#40;'M' =&#62; 1000, 'CM' =&#62; 900, 'D' =&#62; 500, 'CD' =&#62; [...]]]></description>
			<content:encoded><![CDATA[<p>I needed a function to translate from decimal numbers to their Roman number equivalent.  Here&#8217;s a handy little function I found.</p>

<div class="wp_syntax"><div class="code"><pre class="php" style="font-family:monospace;"><span style="color: #000000; font-weight: bold;">private</span> <span style="color: #000000; font-weight: bold;">function</span> numberToRoman<span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span>
<span style="color: #009900;">&#123;</span>
     <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$num</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
     <span style="color: #000088;">$result</span> <span style="color: #339933;">=</span> <span style="color: #0000ff;">''</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #000088;">$lookup</span> <span style="color: #339933;">=</span> <span style="color: #990000;">array</span><span style="color: #009900;">&#40;</span><span style="color: #0000ff;">'M'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1000</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'CM'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">900</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'D'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">500</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'CD'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">400</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'C'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">100</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'XC'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">90</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'L'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">50</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'XL'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">40</span><span style="color: #339933;">,</span>
     <span style="color: #0000ff;">'X'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">10</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IX'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">9</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'V'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">5</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'IV'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">4</span><span style="color: #339933;">,</span> <span style="color: #0000ff;">'I'</span> <span style="color: #339933;">=&gt;</span> <span style="color: #cc66cc;">1</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
&nbsp;
     <span style="color: #b1b100;">foreach</span> <span style="color: #009900;">&#40;</span><span style="color: #000088;">$lookup</span> <span style="color: #b1b100;">as</span> <span style="color: #000088;">$roman</span> <span style="color: #339933;">=&gt;</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span> <span style="color: #009900;">&#123;</span>
       <span style="color: #000088;">$matches</span> <span style="color: #339933;">=</span> <span style="color: #990000;">intval</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$n</span> <span style="color: #339933;">/</span> <span style="color: #000088;">$value</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$result</span> <span style="color: #339933;">.=</span> <span style="color: #990000;">str_repeat</span><span style="color: #009900;">&#40;</span><span style="color: #000088;">$roman</span><span style="color: #339933;">,</span> <span style="color: #000088;">$matches</span><span style="color: #009900;">&#41;</span><span style="color: #339933;">;</span>
       <span style="color: #000088;">$n</span> <span style="color: #339933;">=</span> <span style="color: #000088;">$n</span> <span style="color: #339933;">%</span> <span style="color: #000088;">$value</span><span style="color: #339933;">;</span>
     <span style="color: #009900;">&#125;</span>
     <span style="color: #b1b100;">return</span> <span style="color: #000088;">$result</span><span style="color: #339933;">;</span>
<span style="color: #009900;">&#125;</span></pre></div></div>

]]></content:encoded>
			<wfw:commentRss>http://www.phpdeveloping.co.za/numbers/decimal-to-roman-numbers.html/feed</wfw:commentRss>
		<slash:comments>0</slash:comments>
		</item>
	</channel>
</rss>
