Exit
  • Global community
    • Language:
      • Deutsch
      • English
      • Español
      • Français
      • Português
  • 日本語コミュニティ
  • 한국 커뮤니티
0

how to covert roman number to numeric number

Contributor ,
Dec 09, 2010 Dec 09, 2010

hi all

Any idea how to convert roman number(i ii iii......) to numeric number (1 2 3.....)

thank in advance

Mi_D

TOPICS
Scripting
647
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Advisor ,
Dec 09, 2010 Dec 09, 2010

Hey!

I have exactly what you need: http://bit.ly/bFRuoT

Hope that helps!

--

tomaxxi

http://indisnip.wordpress.com/

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Contributor ,
Dec 09, 2010 Dec 09, 2010

Hi tomaxxi

Thank its working fine

I_D

Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines
Engaged ,
Jul 31, 2021 Jul 31, 2021
LATEST

Hi @tomaxxi,

Here is the way to convert roman to int and int to roman.

 

 

RomanToInteger('MCMLXXXII');//MCMLXXXII:1982
IntegerToRoman(1982);//1982:MCMLXXXII

function RomanToInteger(str) {
    var map = { 'I': 1, 'V': 5, 'X': 10, 'L': 50, 'C': 100, 'D': 500, 'M': 1000 };
    var result = 0;

    for (var i = 0; i < str.length; i++) {
        if (i && map[str.charAt(i)] > map[str.charAt(i - 1)]) {
            result += (map[str.charAt(i)] - (map[str.charAt(i - 1)] * 2));
        }
        else {
            result += map[str.charAt(i)];
        }
    }
    return result;
}

function IntegerToRoman(num) {
    var units = ['', 'I', 'II', 'III', 'IV', 'V', 'VI', 'VII', 'VIII', 'XI'];
    var tens = ['', 'X', 'XX', 'XXX', 'XL', 'L', 'LX', 'LXX', 'LXXX', 'XC'];
    var hundreds = ['', 'C', 'CC', 'CCC', 'CD', 'D', 'DC', 'DCC', 'DCCC', 'CM'];
    var thousands = ['', 'M', 'MM', 'MMM'];

    return thousands[parseInt(num / 1000)] +
        hundreds[parseInt((num % 1000) / 100)] +
        tens[parseInt((num % 100) / 10)] +
        units[num % 10];
}

 

 

-Sumit
Translate
Report
Community guidelines
Be kind and respectful, give credit to the original source of content, and search for duplicates before posting. Learn more
community guidelines