Languages :: PHP :: roman numerals |
|||
| By: roe1and |
Date: 06/11/2007 15:29:59 |
Points: 20 | Status: Answered Quality : Excellent |
| i fixed this using a bucket load of if statements(if ($e = "i")$e = 1;if ($e = "ii")$e = 2;, etc)and even though i'm asking this question, i'm not really expecting an answer. is there a relatively simple way of changing roman numerals into arabic using php? | |||
| By: VGR | Date: 06/11/2007 19:36:03 | Type : Answer |
|
| yes and no. No because I can't get out the code ready for use from my head ;-) and yes because the reverse is a lot more complicated and is a classical IT/Maths class problem (at least, it was when I was in class ;-) if you're not too in a hurry, I can try to retrieve some algorithm of mine : I've to dig into 30 years of archive, so be patient ;-) if you're in a hurry, I would say from memory that a Roman number, say MCXL, can be transformed in an Hindic number (²) by simply moving from left to right by adding letter values ***in descending order*** and by changing the sign of the last intermediary summation when a sign of greater value arises. Exemple : CXL : 100 ; +10=110 ; 50 encountered : 10 was in fact -10 ; 100-10+50=140 CQFD (you may substract 2*last_value from the intermediary sum IMHO) (²) no arab influence in there, only transportation of the knowledge from the Persians, themselves from India etc ; Arabs themselves call those signs "hindis numbers". |
|||
| By: roe1and | Date: 06/11/2007 19:51:11 | Type : Comment |
|
| please don't go to that much trouble. i was only asking out of curiosity. my script only needs to go to 20 or so so my if statements works ok. thanks for your help though. | |||
|
Do register to be able to answer |
|||
©2010 These pages are served without commercial sponsorship. (No popup ads, etc...). Bandwidth abuse increases hosting cost forcing sponsorship or shutdown. This server aggressively defends against automated copying for any reason including offline viewing, duplication, etc... Please respect this requirement and DO NOT RIP THIS SITE.
Please DO link to this page!








