Author Topic: Dec to Roman Numerial  (Read 10893 times)

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Dec to Roman Numerial
« on: May 01, 2005, 02:44:03 PM »
Ok here's what I have so far.  Written in PHP of course.  The problem is that the border trick, while working, doesn't look that great.  I need to find another method to put a bar over the symbol.  This craps out at about 100,00 posts but I figure we have time to deal with that.


function decRN($num)
{
$values = array (
	
100000 => array (
	
	
array(
'C'1),
	
	
),
	
90000 => array (
	
	
array(
'X'1),
	
	
array(
'C'1),
	
	
),
	
50000 => array (
	
	
array(
'L'1),
	
	
),
	
40000 => array (
	
	
array(
'X'1),
	
	
array(
'L'1),
	
	
),
	
10000 => array (
	
	
array(
'X'1),
	
	
),
	
9000 => array (
	
	
array(
'M'0),
	
	
array(
'X'1),
	
	
),
	
5000 => array (
	
	
array(
'V'1),
	
	
),
	
4000 => array (
	
	
array(
'M'0),
	
	
array(
'V'1),
	
	
),
	
1000 => array(
	
	
array(
'M'0),
	
	
),
	
900 =>  array (
	
	
array(
'C'0),
	
	
array(
'M'0),
	
	
),
	
500 =>  array (
	
	
array(
'D'0),
	
	
),
	
400 =>  array (
	
	
array(
'C'0),
	
	
array(
'D'0),
	
	
),
	
100 =>  array (
	
	
array(
'C'0),
	
	
),
	
90 =>   array (
	
	
array(
'X'0),
	
	
array(
'C'0),
	
	
),
	
50 =>   array (
	
	
array(
'L'0),
	
	
),
	
40 =>   array (
	
	
array(
'X'0),
	
	
array(
'L'0),
	
	
),
	
10 =>   array (
	
	
array(
'X'0),
	
	
),
	
=>    array (
	
	
array(
'I'0),
	
	
array(
'X'0),
	
	
),
	
=>    array (
	
	
array(
'V'0),
	
	
),
	
=>    array (
	
	
array(
'I'0),
	
	
array(
'V'0),
	
	
),
	
=>    array (
	
	
array(
'I'0),
	
	
),
	
);
	
$str '';
	
foreach(
$values as $val => $data )
	
{
	
	
while ( 
$num >= $val )
	
	
{
	
	
	
foreach (
$data AS $sym)
	
	
	
	
$str.= '<span style="border-top: ' $sym[1] . 'px solid black">' $sym[0] . '</span>';
	
	
	
$num -= $val;
	
	
}
	
}
	
return 
$str;
}


So if anyone has any ideas of a better way to get the bar over the symbol please let me know
« Last Edit: May 01, 2005, 03:19:40 PM by Mike »

jverkoey

  • Jackass III
  • Posts: 226
  • Karma: +12/-2
    • http://TheJeffFiles.com/
Dec to Roman Numerial
« Reply #1 on: May 01, 2005, 03:01:27 PM »
We could just add our own symbols.

I uploaded source which is a tad better looking, though written in C.
-Jeff Verkoeyen

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Dec to Roman Numerial
« Reply #2 on: May 01, 2005, 03:07:22 PM »
Yes but your code requires more effert.  Since PHP handles arrays very nicely its simpler to do it my way.

Also yours doesn't seem to handle over 4999.  The problem with adding our own is just graphics.  But if someone made up a nice set I could easily manipulate the code to use the graphics.

jverkoey

  • Jackass III
  • Posts: 226
  • Karma: +12/-2
    • http://TheJeffFiles.com/
Dec to Roman Numerial
« Reply #3 on: May 01, 2005, 03:11:34 PM »
Maybe we should just keep normal decimal output.... :dunno:

*stabs self*
« Last Edit: May 01, 2005, 03:33:10 PM by jverkoey »
-Jeff Verkoeyen

Mike

  • Jackass In Charge
  • Posts: 11248
  • Karma: +168/-32
  • Ex Asshole - a better and more caring person.
Dec to Roman Numerial
« Reply #4 on: May 01, 2005, 03:13:55 PM »
Thats a discussion for the poll not here.