Posted: 4th Jun 2003 2:30
Preface
I recently had need to convert a number to Roman Numerals and wrote a universal function for the task. Please feel free to use this function without credit.

Usage
string=romanNumeral(integer)

Limitation
The Roman Numeral for 5,000 is not present in the ASCII table, therefor the function can only return a value of 3,999 or less.

There's a 1000 diference? That is because the numeral for 4,000 actually uses the numeral for 5,000 to depict it.

The numeral itself is a V with a horizontal line above it, I have tried to use extended ASCII characters to reposition the cursor but DBPro doesn't seem to support that. This is not a failing of DBPro really as such conventions have not existed in the Windows era.

The Romans had no numeral for the number 0 and therefor cannot express negative numbers.

The function therefor is limited to the range 1-3999.
Posted: 18th Jun 2003 0:30
code only works once... then fails, see this example below

+ Code Snippet
do
print "number ", 100, "equals ,",romanNumeral(100)

loop


function romanNumeral(number)
   thousand=number/1000
   if thousand=1 then numeral$="M"
   if thousand=2 then numeral$="MM"
   if thousand=3 then numeral$="MMM"
   number=number-(thousand*1000)

   hundred=number/100
   if hundred=1 then numeral$=numeral$+"C"
   if hundred=2 then numeral$=numeral$+"CC"
   if hundred=3 then numeral$=numeral$+"CCC"
   if hundred=4 then numeral$=numeral$+"CD"
   if hundred=5 then numeral$=numeral$+"D"
   if hundred=6 then numeral$=numeral$+"DC"
   if hundred=7 then numeral$=numeral$+"DCC"
   if hundred=8 then numeral$=numeral$+"DCCC"
   if hundred=9 then numeral$=numeral$+"CM"
   number=number-(hundred*100)

   ten=number/10
   if ten=1 then numeral$=numeral$+"X"
   if ten=2 then numeral$=numeral$+"XX"
   if ten=3 then numeral$=numeral$+"XXX"
   if ten=4 then numeral$=numeral$+"XL"
   if ten=5 then numeral$=numeral$+"L"
   if ten=6 then numeral$=numeral$+"LX"
   if ten=7 then numeral$=numeral$+"LXX"
   if ten=8 then numeral$=numeral$+"LXXX"
   if ten=9 then numeral$=numeral$+"XC"
   number=number-(ten*10)

   if number=1 then numeral$=numeral$+"I"
   if number=2 then numeral$=numeral$+"II"
   if number=3 then numeral$=numeral$+"III"
   if number=4 then numeral$=numeral$+"IV"
   if number=5 then numeral$=numeral$+"V"
   if number=6 then numeral$=numeral$+"VI"
   if number=7 then numeral$=numeral$+"VII"
   if number=8 then numeral$=numeral$+"VIII"
   if number=9 then numeral$=numeral$+"IX"
endfunction numeral$
Posted: 18th Jun 2003 22:48
I executed your example and it returned the correct result "C" every time.
Posted: 19th Jun 2003 0:25
Not in DBC, in the function you should add numeral$="". Then it will work. In DBC the first time it gives "C" then "CC" then "CCC", you know what I mean. Maybe in DBPro the variable is a local variable that only exist in the function, but in DBC it remembers the variable. This way the function will be dbpro compatible:
+ Code Snippet
function romanNumeral(number)
   numeral$=""
   thousand=number/1000
   if thousand=1 then numeral$="M"
   if thousand=2 then numeral$="MM"
   if thousand=3 then numeral$="MMM"
   number=number-(thousand*1000)

   hundred=number/100
   if hundred=1 then numeral$=numeral$+"C"
   if hundred=2 then numeral$=numeral$+"CC"
   if hundred=3 then numeral$=numeral$+"CCC"
   if hundred=4 then numeral$=numeral$+"CD"
   if hundred=5 then numeral$=numeral$+"D"
   if hundred=6 then numeral$=numeral$+"DC"
   if hundred=7 then numeral$=numeral$+"DCC"
   if hundred=8 then numeral$=numeral$+"DCCC"
   if hundred=9 then numeral$=numeral$+"CM"
   number=number-(hundred*100)

   ten=number/10
   if ten=1 then numeral$=numeral$+"X"
   if ten=2 then numeral$=numeral$+"XX"
   if ten=3 then numeral$=numeral$+"XXX"
   if ten=4 then numeral$=numeral$+"XL"
   if ten=5 then numeral$=numeral$+"L"
   if ten=6 then numeral$=numeral$+"LX"
   if ten=7 then numeral$=numeral$+"LXX"
   if ten=8 then numeral$=numeral$+"LXXX"
   if ten=9 then numeral$=numeral$+"XC"
   number=number-(ten*10)

   if number=1 then numeral$=numeral$+"I"
   if number=2 then numeral$=numeral$+"II"
   if number=3 then numeral$=numeral$+"III"
   if number=4 then numeral$=numeral$+"IV"
   if number=5 then numeral$=numeral$+"V"
   if number=6 then numeral$=numeral$+"VI"
   if number=7 then numeral$=numeral$+"VII"
   if number=8 then numeral$=numeral$+"VIII"
   if number=9 then numeral$=numeral$+"IX"
endfunction numeral$
Posted: 20th Jun 2003 2:37
Thanks for clearing that up RTSpider cheers