Looks pretty good, thanks for sharing. One thing I noticed is it fails on edge cases of 49, 99, 490-499, 990-999, etc. Instead of outputting XLIX, XCIX, CDXCIX, etc is outputs IL, IC, XD-ID, XM-IM.
Except the romans didn’t write 4 as IV 9 as IX etc - at least this subtractive form was not consistently used
4 was more often IIII
8 was more often IIII?III
The abbreviations we use now were not common in the Romans times
And then do you write MIM for 1999 ? If so why not MXM for 1990 ?
The Keyser article referenced on the wikipedia page is a good read
Keyser, Paul (1988). “The Origin of the Latin Numerals 1 to 1000”. American Journal of Archaeology 92: 529546.
I’ll dig up my History of Computation book as well as it has a segment on this
Function dec_to_roman(n As Integer) As String
Dim numero As Long, v As Variant, s As String, x As Variant
If n < 1 Or n > 3999 Then
dec_to_roman = "#VALORE!"
Exit Function
End If
v = Split(split_number(CStr(n)), ";")
For Each x In v
s = s & analizza(CInt(x))
Next
dec_to_roman = s
End Function
Private Function split_number(n As String) As String
Dim s As String, i As Integer
For i = 1 To Len(n)
s = s & Mid(n, i, 1) * 10 ^ (Len(n) - i) & ";"
Next
split_number = Left(s, Len(s) - 1)
End Function
Private Function analizza(n As Integer) As String
Dim s As String, i As Integer
Select Case n
Case Is > 900
i = n 1000
s = String(i, "M")
Case 100 To 900
i = n 100
Select Case i
Case 1 To 3
s = String(i, "C")
Case 4
s = "CD"
Case 5
s = "D"
Case 6 To 8
s = "D" & String(i - 5, "C")
Case 9
s = "CM"
End Select
Case 10 To 90
i = n 10
Select Case i
Case 1 To 3
s = String(i, "X")
Case 4
s = "XL"
Case 5
s = "L"
Case 6 To 8
s = "L" & String(i - 5, "X")
Case 9
s = "XC"
End Select
Case Else
i = n
Select Case i
Case 1 To 3
s = String(i, "I")
Case 4
s = "IV"
Case 5
s = "V"
Case 6 To 8
s = "V" & String(i - 5, "I")
Case 9
s = "IX"
End Select
End Select
analizza = s
Proper latin, no doubt. But it would make sense that plebeians, especially in the provinces distant from Rome, used simplified forms just the same as today, in English or in French, spelling is steadily presented in slanguish spelling. Da computa is workin’
Wrong for purists, denatured Latin eventually became French or Spanish which are full fledged languages today. I would not dare speaking about other languages I do not know but the fact is “pure” Latin probably existed only in the capital. My point was not to say the folklorik local variations were right, but just that they probably existed.
Just like today Belgian and Swiss have different ways of saying “70” or “80” in French than the natives of France.
“Septente” in Belgium and Switzerland, for 70 “soixante dix” in France.
“Octante” in Switzerland, for 80 “quatre vingt” in France.
[quote=153060:@Massimo Valle]Yeah thats because french used to count with fingers and they have only twenty.
Maybe the same reason for writing IIII instead if IV.
:P[/quote]
The history of writing systems is full of artifacts and strange things along history. That is what makes it interesting.
Languages evolve differently in different countries because of local contexts, origins, and even political decisions. For example, French as it is known in France today had to be forced on the regions. Between 1880 and 1940, something like 40 laws were adopted in France to impose the “standard French” and effectively kill all regional dialects. French as it is spoken in Qubec today is an evolution of French as it existed in the northwest regions of France in the 15th, 16th and 17th centuries. The fact that Quebec was completely cut off from France during the British rule period that followed Montcalm’s defeat in Qubec City contributed largely to the isolated evolution of the spoken language in Qubec for many decades. Here is an interesting reference to the evolution of French in France.
Back to topic, I also learned the purist form of roman numbers in latin class, way too long ago.
can’t edit… I meant to add that it makes sense that differnet variations of roman numerals evolved in different regions over the centuries they were current, while a “central” version remained the reference, in the same way that languages evolve. My whole argument on French was an analogy of such evolution.