Results 1 to 3 of 3

Thread: xlsx / ods -

Hybrid View

Previous Post Previous Post   Next Post Next Post
  1. #1
    Registered User
    Join Date: Jun:2013
    Location: >.<
    Posts: 6,182

    xlsx / ods -

    , , ( 543 - - , " ").
    ( ) excel (ms office) ods (libre office) .
    , ( VB ).
    Last edited by user313; 9th December 2015 at 15:27.

  2. #2
    ɐ-əpoɔᴉu⋂ ɐ ə anrieff's Avatar
    Join Date: Apr:2004
    Location: Sofia
    Posts: 8,448
    ( ), :
    Code:
    """Spells numbers, words and lists in Bulgarian."""
    
    ONES = [u"", u"", u"", u"", u"", u"", u"", u"", u"", u""]
    TEENS = [u"", u""] + [x + u"" for x in ONES[2:]]
    TENS = ["", u""] + [one + u"" for one in ONES[2:]]
    HUNDREDS = ["", u"", u"", u""] + [ten + u"" for ten in ONES[4:]]
    THOUSANDS = ["", u"", u" "] + [x + u" " for x in ONES[3:]]
    
    def spell(n):
    	"""Spells a number in Bulgarian, the number should not exceed 10000."""
    	assert n < 10000
    	res = []
    	if n >= 1000:
    		res.append(THOUSANDS[n/1000])
    		n %= 1000
    	if n >= 100:
    		res.append(HUNDREDS[n/100])
    		n %= 100
    	if n >= 20:
    		res.append(TENS[n/10])
    		n %= 10
    		if n:
    			res.append(ONES[n])
    	elif n >= 10:
    		res.append(TEENS[n - 10])
    	else:
    		if n or len(res) == 0:
    			res.append(ONES[n])
    
    	assert len(res) > 0
    	if len(res) > 1:
    		res.insert(len(res) - 1, u"")
    	return " ".join(res)
    , . .
    "640K ught to be enough for anybody" - Bill Gates, 1981
    ::Machine specs::Fract::AGG::::Baileys::blog::YouTube channel

  3. #3
    Registered User
    Join Date: Jun:2013
    Location: >.<
    Posts: 6,182
    . , :
    Code:
    Public Function ToWords(ByVal dblValue As Double, Optional Measure As Variant, Optional Gender As String) As String
        Dim vDigits         As Variant
        Dim vGenderDigits   As Variant
        Dim vValue          As Variant
        Dim lIdx            As Long
        Dim lDigit          As Long
        Dim sResult         As String
        
        '--- init digits (incl. gender ones)
        vDigits = Split("         ")
        vGenderDigits = vDigits
        Select Case Left$(Gender, 1)
        Case vbNullString, "M"
            vGenderDigits(1) = ""
            vGenderDigits(2) = ""
        Case "F"
            vGenderDigits(1) = ""
        End Select
        '--- split input value on decimal point and pad w/ zeroes
        vValue = Mid$(Format$(0, "0.0"), 2, 1)
        vValue = Split(Format$(Abs(dblValue), "0.00##"), vValue)
        vValue(0) = Right$(String$(18, "0") & vValue(0), 18)
        '--- loop input digits from right to left
        For lIdx = 1 To Len(vValue(0))
            If lIdx <= 3 Then
                lDigit = Mid$(vValue(0), Len(vValue(0)) - lIdx + 1, 1)
            Else
                lDigit = Mid$(vValue(0), Len(vValue(0)) - lIdx - 1, 3)
                lIdx = lIdx + 2
            End If
            If lDigit <> 0 Then
                '--- separate by space (first time prepend "" too)
                If LenB(sResult) <> 0 And (lIdx <> 2 Or lDigit <> 1) Then
                    If InStr(sResult, "  ") = 0 Then
                        sResult = "  " & sResult
                    Else
                        sResult = " " & sResult
                    End If
                End If
                Select Case lIdx
                Case 1
                    sResult = vGenderDigits(lDigit) & sResult
                Case 2
                    If lDigit = 1 Then
                        '--- 11 to 19 special wordforms
                        If LenB(sResult) <> 0 Then
                            sResult = Replace(LTrim$(sResult), vGenderDigits(1), "")
                            sResult = Replace(sResult, vGenderDigits(2), "") & ""
                        Else
                            sResult = ""
                        End If
                    Else
                        sResult = IIf(lDigit = 2, "", vDigits(lDigit)) & "" & sResult
                    End If
                Case 3
                    '--- hundreds have special suffixes for 2 and 3
                    Select Case lDigit
                    Case 1
                        sResult = "" & sResult
                    Case 2, 3
                        sResult = vDigits(lDigit) & "" & sResult
                    Case Else
                        sResult = vDigits(lDigit) & "" & sResult
                    End Select
                Case 6
                    '--- thousands are in feminine gender
                    Select Case lDigit
                    Case 1
                        sResult = "" & sResult
                    Case Else
                        sResult = ToWords(lDigit, vbNullString, Gender:="F") & " " & sResult
                    End Select
                Case 9, 12, 15
                    '--- no special cases for bigger values
                    sResult = ToWords(lDigit, vbNullString) & " " & Split("   ")((lIdx - 9) \ 3) _
                        & IIf(lDigit <> 1, "", vbNullString) & sResult
                End Select
            End If
        Next
        '--- handle zero and negative values
        If LenB(sResult) = 0 Then
            sResult = vDigits(0)
        End If
        If dblValue < 0 Then
            sResult = " " & sResult
        End If
        '--- apply measure (use vbNullString for none)
        If IsMissing(Measure) Then
            Measure = ".|."
            Gender = "MF"
        End If
        If LenB(Measure) <> 0 Then
            If Right$(sResult, Len(vDigits(0))) = vDigits(0) And Val(vValue(1)) <> 0 And InStr(Measure, "|") > 0 Then
                sResult = ToWords(IIf(dblValue < 0, -1, 1) * Val(vValue(1)), Split(Measure, "|")(1), Mid$(Gender, 2))
            Else
                sResult = sResult & " " & Split(Measure, "|")(0)
                If Val(vValue(1)) <> 0 Then
                    sResult = sResult & "  " & Val(vValue(1))
                    If InStr(Measure, "|") > 0 Then
                        sResult = sResult & " " & Split(Measure, "|")(1)
                    End If
                End If
                sResult = UCase$(Left$(sResult, 1)) & Mid$(sResult, 2)
            End If
        End If
        ToWords = sResult
    End Function
    Libre-,
    Last edited by user313; 9th December 2015 at 16:48.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  

Copyright © 1999-2011 . .
iskamPC.com | mobility.BG | Bloody's Techblog | | 3D Vision Blog |