Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Convert Numbers To Roman Numerals With Javascript
#1
This little function can be used to convert numbers to roman numerals.

Code:
function convertToRoman(num) {
  var lookup = {M:1000,CM:900,D:500,CD:400,C:100,XC:90,L:50,XL:40,X:10,IX:9,V:5,IV:4,I:1};
  var roman = '',i;
  for ( i in lookup ) {
    while ( num >= lookup[i] ) {
      
      roman += i;
      num -= lookup[i];
      
    }
  }
  return roman;
}
convertToRoman(233)

It takes so long to learn simplicity.
Facebook Share


Possibly Related Threads...
Thread
  HELP: How Can I Create A Javascript Ads Rotator For My Site
  Beginner Javascript Coding Mistakes To Avoid
  Concatenate Many Arrays Uniquely With Javascript
  Javascript Time Ago Function
  Shortest Code For Random Number Between 1 And N In Javascript
  Javascript Text Editor Right In Your Browser In One Line Of Code
  Getting Current Location With Javascript
  How To Check If Javascript Object Is Empty
  How To Create An Image Slider With Javascript
  TUTORIAL: How To Make A Digtal Clock With Javascript




Users browsing this thread: 1 Guest(s)