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
    10

    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 Forum Police
    Join Date
    Sep 2008
    Location
    Madgaon, Goa, India
    Posts
    12,059
    Rep Power
    24

    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
    10

Similar Threads

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

Posting Permissions

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