joi, 12 ianuarie 2012

conversie numar din cifre in litere romana / romanian

'Aveti aici o functie VB pe care o puteti introduce in excel, access, etc. si care face o astfel de conversie din numere in litere:
Function SpellNumber(ByVal MyNumber)
Dim Dollars, Cents, Temp
Dim DecimalPlace
ReDim Place(9) As String
Place(2) = "mii"
Place(3) = "milioane"
Place(4) = "miliarde"
Place(5) = "trilioane"
Place(6) = "catralioane"
Place(7) = "chintilioane"
' String representation of amount.
MyNumber = Trim(Str(MyNumber))
' Position of decimal place 0 if none.
DecimalPlace = InStr(MyNumber, ".")
' Convert cents and set MyNumber to dollar amount.
If DecimalPlace > 0 Then
count = 0
Cents = GetTens(Left(Mid(MyNumber, DecimalPlace + 1) & _
"00", 2))
MyNumber = Trim(Left(MyNumber, DecimalPlace - 1))
End If
count = 1
Do While MyNumber <> ""
Temp = GetHundreds(Right(MyNumber, 3))
'MsgBox Temp + "===" + Str(count)

If Temp <> "" Then
If Temp = "unu" And count = 2 Then
Dollars = "unamie" & Dollars
Else


If Temp = "doi" And count = 2 Then
Dollars = "douamii" & Dollars
Else
If Temp = "doi" And count = 3 Then
Dollars = "douamilioane" & Dollars
Else
If Temp = "unu" And count = 3 Then
Dollars = "unmilion" & Dollars
Else
Dollars = Temp & Place(count) & Dollars
End If

End If

End If
End If
End If

If Len(MyNumber) > 3 Then
MyNumber = Left(MyNumber, Len(MyNumber) - 3)
Else
MyNumber = ""
End If
count = count + 1
Loop
Select Case Dollars
Case ""
Dollars = "zerolei"
Case "unu"
Dollars = "unleu"
Case Else
Dollars = Dollars & "lei"
End Select

Select Case Cents
Case ""
Cents = " sizerobani"
Case "siunu"
Cents = "siunban"
Case Else
Cents = "si" & Cents & "bani"
End Select
SpellNumber = Dollars & Cents
End Function

' Converts a number from 100-999 into text
Function GetHundreds(ByVal MyNumber)
Dim Result As String
If Val(MyNumber) = 0 Then Exit Function
MyNumber = Right("000" & MyNumber, 3)
' Convert the hundreds place.
If Mid(MyNumber, 1, 1) <> "0" Then


Select Case Val(Mid(MyNumber, 1, 1))
Case 1: Result = "unasuta"
Case 2: Result = "douasute"
Case Else:
Result = GetDigit(Mid(MyNumber, 1, 1)) & "sute"
End Select
End If
' Convert the tens and ones place.
If Mid(MyNumber, 2, 1) <> "0" Then
Result = Result & GetTens(Mid(MyNumber, 2))
Else
Result = Result & GetDigit(Mid(MyNumber, 3))
End If
GetHundreds = Result
End Function

' Converts a number from 10 to 99 into text.
Function GetTens(TensText)
Dim Result As String
Result = "" ' Null out the temporary function value.
If Val(Left(TensText, 1)) = 1 Then ' If value between 10-19...
Select Case Val(TensText)
Case 10: Result = "zece"
Case 11: Result = "unsprezece"
Case 12: Result = "doisprezece"
Case 13: Result = "treisprezece"
Case 14: Result = "paisprezece"
Case 15: Result = "cincisprezece"
Case 16: Result = "saisprezece"
Case 17: Result = "saptesprezece"
Case 18: Result = "optsprezece"
Case 19: Result = "nouasprezece"
Case Else
End Select
Else ' If value between 20-99...
Select Case Val(Left(TensText, 1))
Case 2: Result = "douazeci"
Case 3: Result = "treizeci"
Case 4: Result = "patruzeci"
Case 5: Result = "cincizeci"
Case 6: Result = "saizeci"
Case 7: Result = "saptezeci"
Case 8: Result = "optzeci"
Case 9: Result = "nouazeci"
Case Else
End Select




If count > 1 Then
Select Case Val(Right(TensText, 1))
Case 1: Result = Result & "siuna"
Case 2: Result = Result & "sidoua"
Case 0: Result = Result
Case Else
Result = Result & IIf(Val(TensText) < 10, "", "si") & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End Select

Else

Select Case Val(Right(TensText, 1))
Case 1: Result = Result & "siunu"
Case 2:
If count = 0 Then
Result = Result & "doi"
Else
Result = Result & "sidoi"
End If
Case 0: Result = Result
Case Else
Result = Result & IIf(Val(TensText) < 10, "", "si") & GetDigit _
(Right(TensText, 1)) ' Retrieve ones place.
End Select
End If

End If
GetTens = Result
End Function

' Converts a number from 1 to 9 into text.
Function GetDigit(Digit)
Select Case Val(Digit)
Case 1: GetDigit = "unu"
Case 2: GetDigit = "doi"
Case 3: GetDigit = "trei"
Case 4: GetDigit = "patru"
Case 5: GetDigit = "cinci"
Case 6: GetDigit = "sase"
Case 7: GetDigit = "sapte"
Case 8: GetDigit = "opt"
Case 9: GetDigit = "noua"
Case Else: GetDigit = ""
End Select
End Function


'comentati, merci!
' valeriu mocanu
' mocanuvaleriu@yahoo.com

2 comentarii:

  1. Ar fi interesanta adaptarea la noile reglementari:

    56,21 devine cincizecisisaselei, 21 bani

    Banii nu mai sunt transformati.

    RăspundețiȘtergere