Results 1 to 4 of 4
  1. #1
    hector100 is offline Member
    Join Date
    Apr 2009
    Posts
    1
    Rep Power
    0

    Default Roman numeral to Decimal

    Hi Guys,
    Pls I need to know how a program can accept a roman numeral as string and then display it's decimal equivalent. Thanks for your estimeed assistance
    .

  2. #2
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

    Default

    Presumably you know how roman numerals work? You'll need to step through a string character by character, keeping track of the sum you have reached. If you get to a character of higher value than the previous, then you do a subtraction. You probably need to keep track of 3 numbers to deal with stuff like MIIC. You also need to decide whether you're going to try and handle non-standard forms (XCIIX vs. IIC) or just throw a malformed exception.

  3. #3
    DarrylBurke's Avatar
    DarrylBurke is offline Member
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    11,234
    Rep Power
    19

    Default

    I would step through the String backwards, starting at the last character.

    And MIIC, XCIIX and IIC are *all* illegal as roman numerals. 98 can be written one way and one way only: XCVIII. 1098 would be MXCVIII

    db

  4. #4
    OrangeDog's Avatar
    OrangeDog is offline Senior Member
    Join Date
    Jan 2009
    Location
    Cambridge, UK
    Posts
    838
    Rep Power
    6

Similar Threads

  1. Convert roman numerals
    By matzahboy in forum New To Java
    Replies: 4
    Last Post: 02-21-2010, 10:06 PM
  2. Eclipse- Decimal to binary
    By queen_vee in forum New To Java
    Replies: 1
    Last Post: 02-24-2009, 02:17 PM
  3. Percentage/decimal points?
    By Exhonour in forum New To Java
    Replies: 6
    Last Post: 01-16-2009, 10:35 PM
  4. decimal calculations?
    By arnab321 in forum CLDC and MIDP
    Replies: 5
    Last Post: 11-19-2008, 03:36 AM
  5. Convert roman numerals to integers
    By Felissa in forum Advanced Java
    Replies: 2
    Last Post: 07-01-2007, 11:27 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •