I am working on a crystal report which I need to spell out the amount in Spanish. Was trying to get help from chatGPT but are not able to figure out how to fix the formula. Can someone give me some advise?
Dim result As String
Dim n As Number
n = {DealMain.DealtAmount}
Dim units() As String
Dim teens() As String
Dim tens() As String
Dim hundreds() As String
units = Split(" ,uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve", ",")
teens = Split("diez,once,doce,trece,catorce,quince,dieciséis,diecisiete,dieciocho,diecinueve", ",")
tens = Split(" ,diez,veinte,treinta,cuarenta,cincuenta,sesenta,setenta,ochenta,noventa", ",")
hundreds = Split(" ,ciento,doscientos,trescientos,cuatrocientos,quinientos,seiscientos,setecientos,ochocientos,novecientos", ",")
Dim unit As Number
Dim ten As Number
Dim hundred As Number
Dim ProcessHelper As String
ProcessHelper = ""
' Split the number into billions, millions, thousands, and the remainder
Dim billions As Number
Dim millions As Number
Dim thousands As Number
Dim remainder As Number
billions = n 1000000000
millions = (n Mod 1000000000) 1000000
thousands = (n Mod 1000000) 1000
remainder = n Mod 1000
'billions
If billions > 0 Then
ProcessHelper = ""
hundred = billions 100
ten = (billions Mod 100) 10
unit = billions Mod 10
If hundred > 0 Then
If hundred = 1 And ten = 0 And unit = 0 Then
ProcessHelper = "cien "
Else
ProcessHelper = hundreds(hundred) & " "
End If
End If
If ten = 1 Then
ProcessHelper = ProcessHelper & teens(unit) & " "
Else
If ten > 1 Then
ProcessHelper = ProcessHelper & tens(ten) & " "
End If
If unit > 0 Then
ProcessHelper = ProcessHelper & units(unit) & " "
End If
End If
result = result & ProcessHelper & "mil millones "
End If
'millions
If millions > 0 Then
ProcessHelper = ""
hundred = millions 100
ten = (millions Mod 100) 10
unit = millions Mod 10
If hundred > 0 Then
If hundred = 1 And ten = 0 And unit = 0 Then
ProcessHelper = "cien "
Else
ProcessHelper = hundreds(hundred) & " "
End If
End If
If ten = 1 Then
ProcessHelper = ProcessHelper & teens(unit) & " "
Else
If ten > 1 Then
ProcessHelper = ProcessHelper & tens(ten) & " "
End If
If unit > 0 Then
ProcessHelper = ProcessHelper & units(unit) & " "
End If
End If
result = result & ProcessHelper & "millones "
End If
'thousands
If thousands > 0 Then
ProcessHelper = ""
hundred = thousands 100
ten = (thousands Mod 100) 10
unit = thousands Mod 10
If hundred > 0 Then
If hundred = 1 And ten = 0 And unit = 0 Then
ProcessHelper = "cien "
Else
ProcessHelper = hundreds(hundred) & " "
End If
End If
If ten = 1 Then
ProcessHelper = ProcessHelper & teens(unit) & " "
Else
If ten > 1 Then
ProcessHelper = ProcessHelper & tens(ten) & " "
End If
If unit > 0 Then
ProcessHelper = ProcessHelper & units(unit) & " "
End If
End If
If thousands = 1 Then
result = result & "mil "
Else
result = result & ProcessHelper & "mil "
End If
End If
If remainder > 0 Then
ProcessHelper = ""
hundred = remainder 100
ten = (remainder Mod 100) 10
unit = remainder Mod 10
If hundred > 0 Then
If hundred = 1 And ten = 0 And unit = 0 Then
ProcessHelper = "cien "
Else
ProcessHelper = hundreds(hundred) & " "
End If
End If
If ten = 1 Then
ProcessHelper = ProcessHelper & teens(unit) & " "
Else
If ten > 1 Then
ProcessHelper = ProcessHelper & tens(ten) & " "
End If
If unit > 0 Then
ProcessHelper = ProcessHelper & units(unit) & " "
End If
End If
result = result & ProcessHelper
End If
formula = Trim(result)
The formula is giving me incorrect result:
For the amount of 63 million, the formula gives me cincuenta y dos millones (52 mil)
For the amount of 240,786k, the formula gives me ciento treinta millones seiscientos sententa cinco mil (130,675,000)
Can you please help advising why the formula is really off?
Olivia Chan is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.