visitor (0 QPoints)
  • FR
  • EN
  • NL
  • DE
  • ES
315 experts, 1193 registered users, 1659 questions already answered
European Experts Exchange, the very best site for high-quality IT solutions

New Improved Search!

 


05/10/2011 1h30 : Steve Jobs is dead, the father of Apple ][ is gone, we are all orphaned.

Languages :: PHP :: roman numerals


By: roe1and Great Britain  Date: 06/11/2007 15:29:59  English  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 English  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 English  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

EContact
browser fav
page generated in 331.847910 milliseconds

Why Google AdSense ads ?

compteur
 Ranking-Hits PageRank for this page