A bit of an obscure one this, but we are making an English application multi lingual. One function converts numbers to words, and having tried to use the same logic for the French translations it just doesn’t work so I spent a couple of hours this morning porting a Java class to work in LotusScript to perform the function:
'**********************************************************
'*Ported from Java Class found at:
'*http://www.rgagnon.com/javadetails/java-0426.html
'**********************************************************
Class FrenchDecimalFormat
tenNames() As String
uniteNames1() As String
uniteNames2() As String
Sub new()
Redim tenNames(9)
tenNames(0) = ""
tenNames(1) = ""
tenNames(2) = "vingt"
tenNames(3) = "trente"
tenNames(4) = "quarante"
tenNames(5) = "cinquante"
tenNames(6) = "soixante"
tenNames(7) = "soixante"
tenNames(8) = "quatre-vingt"
tenNames(9) = "quatre-vingt"
Redim uniteNames1(19)
uniteNames1(0) = ""
uniteNames1(1) = "un"
uniteNames1(2) = "deux"
uniteNames1(3) = "trois"
uniteNames1(4) = "quatre"
uniteNames1(5) = "cinq"
uniteNames1(6) = "six"
uniteNames1(7) = "sept"
uniteNames1(8) = "huit"
uniteNames1(9) = "neuf"
uniteNames1(10) = "dix"
uniteNames1(11) = "onze"
uniteNames1(12) = "douze"
uniteNames1(13) = "treize"
uniteNames1(14) = "quatorze"
uniteNames1(15) = "quinze"
uniteNames1(16) = "seize"
uniteNames1(17) = "dix-sept"
uniteNames1(18) = "dix-huit"
uniteNames1(19) = "dix-neuf"
Redim uniteNames2(10)
uniteNames2(0) = ""
uniteNames2(1) = ""
uniteNames2(2) = "deux"
uniteNames2(3) = "trois"
uniteNames2(4) = "quatre"
uniteNames2(5) = "cinq"
uniteNames2(6) = "six"
uniteNames2(7) = "sept"
uniteNames2(8) = "huit"
uniteNames2(9) = "neuf"
uniteNames2(10) = "dix"
End Sub
Function convertZeroToHundred(number As Integer) As String
Dim laten As Integer
Dim lUnite As Integer
Dim result As String
Dim joiner As String
laten = Fix(number / 10)
lUnite = number Mod 10
result = ""
If laten = 1 Or laten = 7 Or laten = 9 Then
lUnite = lUnite + 10
End If
joiner = ""
If laten > 1 Then
joiner = "-"
End If
If lUnite = 0 Then
joiner = ""
Elseif lUnite = 1 Then
If laten = 8 Then
joiner = "-"
Else
joiner = " et "
End If
Elseif lUnite = 11 Then
If laten = 7 Then
joiner = " et "
End If
End If
If laten = 0 Then
result = uniteNames1(lUnite)
Elseif laten = 8 Then
If lUnite = 0 Then
result = tenNames(laten)
Else
result = tenNames(laten) + joiner + uniteNames1(lUnite)
End If
Else
result = tenNames(laten) + joiner + uniteNames1(lUnite)
End If
convertZeroToHundred = result
End Function
Function convertLessThanOneThousand(number As Integer)
Dim hundreds As Integer
Dim remainder As Integer
Dim strRemainder As String
Dim result As String
hundreds = Fix(number / 100)
remainder = number Mod 100
strRemainder = convertZeroToHundred(remainder)
If hundreds = 0 Then
result = strRemainder
Elseif hundreds = 1 Then
If remainder > 0 Then
result = "cent " + strRemainder
Else
result = "cent"
End If
Else
If remainder > 0 Then
result = uniteNames2(hundreds) + " cent " + strRemainder
Else
result = uniteNames2(hundreds) + " cents"
End If
End If
convertLessThanOneThousand = result
End Function
Function convert(number As Double)
Dim snumber As String
Dim billions As Integer
Dim millions As Integer
Dim hundredthousands As Integer
Dim thousands As Integer
Dim strBillions As String
Dim strMillions As String
Dim strHundredThousands As String
Dim strThousands As String
Dim result As String
If number = 0 Then
convert = "zéro"
Exit Function
End If
snumber = Cstr(number)
snumber = Format$(number, "000000000000")
billions = Cint(Left$(snumber, 3)) ' XXXnnnnnnnnn
millions = Cint(Mid$(snumber, 4,3)) ' nnnXXXnnnnnn
hundredthousands = Cint(Mid$(snumber, 7, 3)) ' nnnnnnXXXnnn
thousands = Cint(Mid$(snumber, 10, 3)) ' nnnnnnnnnXXX
If billions = 0 Then
strBillions = ""
Elseif billions = 1 Then
strBillions = convertLessThanOneThousand(billions) + " milliard "
Else
strBillions = convertLessThanOneThousand(billions) + " milliards "
End If
result = strBillions
If millions = 0 Then
strMillions = ""
Elseif millions = 1 Then
strMillions = convertLessThanOneThousand(millions) + " million "
Else
strMillions = convertLessThanOneThousand(millions) + " millions "
End If
result = result + strMillions
If hundredthousands = 0 Then
strHundredThousands = ""
Elseif hundredthousands = 1 Then
strHundredThousands = "mille "
Else
strHundredThousands = convertLessThanOneThousand(hundredthousands) + " mille "
End If
result = result + strHundredThousands
strThousands = convertLessThanOneThousand(thousands)
result = result + strThousands
convert = result
End Function
End Class���
Tags: Show-N-Tell Thursday