ioa747 Posted July 29, 2023 Share Posted July 29, 2023 (edited) Convert numbers into words SpellNumber.au3 expandcollapse popup; https://www.autoitscript.com/forum/topic/210620-spellnumber-function-to-convert-numbers-to-words/?do=edit ;---------------------------------------------------------------------------------------- ; Title...........: SpellNumber.au3 ; Description.....: Convert numbers into words ; AutoIt Version..: 3.3.16.1 Author: ioa747 ; https://support.microsoft.com/en-au/office/convert-numbers-into-words-a0d166fb-e1ea-4090-95c8-69442cd55d98 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ConsoleWrite("" & SpellNumber(1100.25) & @CRLF) ConsoleWrite("" & SpellNumber(105533) & @CRLF) ;---------------------------------------------------------------------------------------- Func SpellNumber($MyNumber) Local $Coin = "Euro" ; Dollar Local $SubCoin = "Cent" ; Cent Local $Units, $SubUnits, $Temp Local $DecimalPlace, $Count Local $Place[9] $Place[2] = " Thousand " $Place[3] = " Million " $Place[4] = " Billion " $Place[5] = " Trillion " ; String representation of amount. $MyNumber = StringStripWS(String($MyNumber), 8) ; Position of decimal place 0 if none. $DecimalPlace = StringInStr($MyNumber, ".") ; Convert $SubUnits and set $MyNumber to dollar amount. If $DecimalPlace > 0 Then $SubUnits = GetTens(StringLeft(StringMid($MyNumber, $DecimalPlace + 1) & "00", 2)) $MyNumber = StringStripWS(StringLeft($MyNumber, $DecimalPlace - 1), 8) EndIf $Count = 1 While $MyNumber <> "" $Temp = GetHundreds(StringRight($MyNumber, 3)) If $Temp <> "" Then $Units = $Temp & $Place[$Count] & $Units If StringLen($MyNumber) > 3 Then $MyNumber = StringLeft($MyNumber, StringLen($MyNumber) - 3) Else $MyNumber = "" EndIf $Count = $Count + 1 WEnd Switch $Units Case "" $Units = "No " & $Coin & "s" Case "One" $Units = "One " & $Coin Case Else $Units = $Units & " " & $Coin & "s" EndSwitch Switch $SubUnits Case "" $SubUnits = " and No " & $SubCoin & "s" Case "One" $SubUnits = " and One " & $SubCoin Case Else $SubUnits = " and " & $SubUnits & " " & $SubCoin & "s" EndSwitch Return StringStripWS($Units & $SubUnits, 1 + 2 + 4) EndFunc ;==>SpellNumber ;---------------------------------------------------------------------------------------- Func GetHundreds($MyNumber) ; Converts a number from 100-999 into text Local $Result If Int($MyNumber) = 0 Then Return $MyNumber = StringRight("000" & $MyNumber, 3) ; Convert the hundreds place. If StringMid($MyNumber, 1, 1) <> "0" Then $Result = GetDigit(StringMid($MyNumber, 1, 1)) & " Hundred " EndIf ; Convert the tens and ones place. If StringMid($MyNumber, 2, 1) <> "0" Then $Result = $Result & GetTens(StringMid($MyNumber, 2)) Else $Result = $Result & GetDigit(StringMid($MyNumber, 3)) EndIf Return $Result EndFunc ;==>GetHundreds ;---------------------------------------------------------------------------------------- Func GetTens($TensText) ; Converts a number from 10 to 99 into text. Local $Result = "" ; Null out the $Temporary function value. If Int(StringLeft($TensText, 1)) = 1 Then ; If value between 10-19... Switch Int($TensText) Case 10 $Result = "Ten" Case 11 $Result = "Eleven" Case 12 $Result = "Twelve" Case 13 $Result = "Thirteen" Case 14 $Result = "Fourteen" Case 15 $Result = "Fifteen" Case 16 $Result = "Sixteen" Case 17 $Result = "Seventeen" Case 18 $Result = "Eighteen" Case 19 $Result = "Nineteen" Case Else EndSwitch Else ; If value between 20-99... Switch Int(StringLeft($TensText, 1)) Case 2 $Result = "Twenty " Case 3 $Result = "Thirty " Case 4 $Result = "Forty " Case 5 $Result = "Fifty " Case 6 $Result = "Sixty " Case 7 $Result = "Seventy " Case 8 $Result = "Eighty " Case 9 $Result = "Ninety " Case Else EndSwitch $Result = $Result & GetDigit(StringRight($TensText, 1)) ; Retrieve ones place. EndIf Return $Result EndFunc ;==>GetTens ;---------------------------------------------------------------------------------------- Func GetDigit($Digit) ; Converts a number from 1 to 9 into text. Local $Result Switch Int($Digit) Case 1 $Result = "One" Case 2 $Result = "Two" Case 3 $Result = "Three" Case 4 $Result = "Four" Case 5 $Result = "Five" Case 6 $Result = "Six" Case 7 $Result = "Seven" Case 8 $Result = "Eight" Case 9 $Result = "Nine" Case Else $Result = "" EndSwitch Return $Result EndFunc ;==>GetDigit ;---------------------------------------------------------------------------------------- Edited July 30, 2023 by ioa747 prettify SmOke_N and Dan_555 2 I know that I know nothing Link to comment Share on other sites More sharing options...
Andreik Posted July 29, 2023 Share Posted July 29, 2023 (edited) I was going to say that it would be nice to implement it for different languages but I remembered this picture. Imagine such a function that will work with danish numerals. Edited July 29, 2023 by Andreik Dan_555 and ioa747 1 1 When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Dan_555 Posted July 30, 2023 Share Posted July 30, 2023 German 29.929.292 would spell "nine and twenty millions nine hundred nine and twenty thousand two hundred two and ninety." It can be confusing when you come from a "90+2" country Andreik 1 Some of my script sourcecode Link to comment Share on other sites More sharing options...
Andreik Posted July 30, 2023 Share Posted July 30, 2023 It is indeed. In Romanian that would be twenty nine millions nine hundreds twenty nine thousands two hundreds ninety two. It would be interesting how different countries form the numerals. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Werty Posted July 30, 2023 Share Posted July 30, 2023 (edited) Dont know who made that pic, that's from the very old days, in Denmark it's like in Germany, 2+90 (2 & 90). Edited July 30, 2023 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Moderators Melba23 Posted July 30, 2023 Moderators Share Posted July 30, 2023 ioa747, You might find this old thread interesting: That was my attempt at counting in French - I will have a go at a Spanish version this week when I find time. M23 ioa747 1 Any of my own code posted anywhere on the forum is available for use by others without any restriction of any kind Open spoiler to see my UDFs: Spoiler ArrayMultiColSort ---- Sort arrays on multiple columnsChooseFileFolder ---- Single and multiple selections from specified path treeview listingDate_Time_Convert -- Easily convert date/time formats, including the language usedExtMsgBox --------- A highly customisable replacement for MsgBoxGUIExtender -------- Extend and retract multiple sections within a GUIGUIFrame ---------- Subdivide GUIs into many adjustable framesGUIListViewEx ------- Insert, delete, move, drag, sort, edit and colour ListView itemsGUITreeViewEx ------ Check/clear parent and child checkboxes in a TreeViewMarquee ----------- Scrolling tickertape GUIsNoFocusLines ------- Remove the dotted focus lines from buttons, sliders, radios and checkboxesNotify ------------- Small notifications on the edge of the displayScrollbars ----------Automatically sized scrollbars with a single commandStringSize ---------- Automatically size controls to fit textToast -------------- Small GUIs which pop out of the notification area Link to comment Share on other sites More sharing options...
Andreik Posted July 30, 2023 Share Posted July 30, 2023 22 minutes ago, Werty said: Dont know who made that pic, that's from the very old days, in Denmark it's like in Germany, 2+90 (2 & 90). Even if it's old fashion yet it's still a valid form of numerals. Someone explained it that way: Quote The full, old fashioned way of saying 92 in Danish is “tooghalvfemsindstyve”, but it’s just called “tooghalvfems” in daily life. It is broken down to “to-og-halv-fem-sinds-tyve”, which literally translates to “two-and-half-five-times-twenty”. 2+(-0.5+5)•20=92. It’s an old base 20 system, rather than a base 10 system. Danish has a way of counting down in certain cases, so when you say “half-five” it’s 5 and halfway down to the next whole number down, so 4.5. You can also say “halvanden” (halv-anden) which is “half-second/two” which is halfway down to 1 from 2, so 1.5. And so on. Are you danish? Can you confirm this? When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Werty Posted July 30, 2023 Share Posted July 30, 2023 (edited) 20 minutes ago, Andreik said: Are you danish? Can you confirm this? Yes I'm Danish, and yes I can confirm it, but noone uses it anymore, hence the "from the very old days". Edit Though the way we speak it, like "50" we do still say "Halvtreds" (half sixty), but you dont think about it. Maybe I misunderstood you. Also 90 is said as "Half fifty", so maybe yes. I was looking at the numbers in the pic, which I as a Dane dont understand at all, it's not something we use in the daily. The last part "+20" is long gone from our language. If you like I can write the whole from 1 to 100 as we speak it. Like 70 is "half forty" 10 "Ten" 20 "Twenty" 30 "thirty" 40 "Forty" 50 "Half sixty" 60 "Sixty" 70 "Half forty" 80 "Eighty" 90 "Half Fifty" 100 "hundred" We dont use "half sixty twenties" anymore. Edited July 30, 2023 by Werty Some guy's script + some other guy's script = my script! Link to comment Share on other sites More sharing options...
Andreik Posted July 30, 2023 Share Posted July 30, 2023 This is very interesting. I am still amazed because I find this system counterintuitive but as you said for danish people it's natural. Probably the most interesting part for me it's when you said 50 it's half sixty and 70 it's half forty. When the words fail... music speaks. Link to comment Share on other sites More sharing options...
Mateocedillo Posted July 31, 2023 Share Posted July 31, 2023 Hi, I have been trying to do something for Spanish, but there are things that I surely have to improve. Here's my code: expandcollapse popup#include <MsgBoxConstants.au3> #include <StringConstants.au3> #include-once Global $nNumber, $bIncludeAnd, $sNumber MsgBox(0, "Result", NumberToWords(23456, False)) Func NumberToWords($nNumber, $bIncludeAnd = True) Local $aOnes = StringSplit("cero,uno,dos,tres,cuatro,cinco,seis,siete,ocho,nueve", ",") local $aTildes = StringSplit("dós,trés,cuatro,cinco,séis,siete,ocho,nueve", ",") Local $aTeens = StringSplit("diez,once,doce,trece,catorce,quince,dieciseis,diecisiete,dieciocho,diecinueve", ",") Local $aTens = StringSplit("dieci,veinte,treinta,cuarenta,cincuenta,sesenta,setenta,ochenta,noventa", ",") Local $aHundreds = StringSplit("cien,doscientos,trescientos,cuatrocientos,quinientos,seiscientos,setecientos,ochocientos,novecientos", ",") local $bTilde Local $sNumber = "" If $nNumber = 0 Then $sNumber = "cero" ElseIf $nNumber < 0 Then $sNumber = "menos " & NumberToWords(Abs($nNumber), $bIncludeAnd) Else If $nNumber >= 1000000 Then $sNumber = NumberToWords(int($nNumber / 1000000), $bIncludeAnd) & " millones " If $bIncludeAnd And mod($nNumber, 1000000) Then $sNumber &= "y " $nNumber = mod($nNumber, 1000000) EndIf switch $nNumber case 1 to 1999 ; para evitar que convierta "uno mil xxx" if StringLen($nNumber) = 4 and StringLeft($nNumber, 1) = 1 then $sNumber &= "mil " case 2000 to 999999 $sNumber &= NumberToWords(Int($nNumber / 1000), $bIncludeAnd) & " mil " EndSwitch If $bIncludeAnd And mod($nNumber, 1000) Then $sNumber &= "y " $nNumber = mod($nNumber, 1000) switch $nNumber $bTilde = False case 100 ; número propio. $sNumber &= "cien " case 101 to 199 ; aquí se tendrá que convertir ciento. $sNumber &= "ciento " case 200 to 999 ; aquí doscientos, trescientos, cuatrocientos, etc. $sNumber &= $aHundreds[Int($nNumber / 100)] & " " EndSwitch $nNumber = mod($nNumber, 100) If $nNumber >= 20 Then if StringRight($nNumber, 1) >= 1 then If not StringLeft($nNumber, 1) = 2 then $bTilde = False $sNumber &= $aTens[Int($nNumber / 10)] & " y " Else $sNumber &= "veinti" $bTilde = True EndIf Else $sNumber &= $aTens[Int($nNumber / 10)] & " " EndIf $nNumber = mod($nNumber, 10) ElseIf $nNumber >= 10 Then $sNumber &= $aTeens[$nNumber - 9] & " " ;$nNumber = StringRight($nNumber, 1) $nNumber = 0 EndIf If $nNumber > 2 Then if $bTilde then $bTilde = False $sNumber &= $aTildes[$nNumber-1] & " " Else $sNumber &= $aOnes[$nNumber+1] & " " EndIf EndIf EndIf Return StringStripWS($sNumber, $STR_STRIPLEADING + $STR_STRIPTRAILING + $STR_STRIPSPACES) EndFunc ioa747 1 Link to comment Share on other sites More sharing options...
ioa747 Posted July 31, 2023 Author Share Posted July 31, 2023 (edited) The first post is a translation from VBA Now, after all that, I present my own approach which is easier to understand, and therefore easier to translate into another language (or so I think) expandcollapse popup; https://www.autoitscript.com/forum/topic/210620-spellnumber-function-to-convert-numbers-to-words/#comment-1521967 ;---------------------------------------------------------------------------------------- ; Title...........: N2T_en.au3 ; Description.....: Convert numbers to English text ; AutoIt Version..: 3.3.16.1 Author: ioa747 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ConsoleWrite("1112.49 " & N2T_en(1112.49) & @CRLF) ConsoleWrite("105533 " & N2T_en(105533) & @CRLF) ;---------------------------------------------------------------------------------------- Func N2T_en($Number) Local $NumPart, $DecPart = "" $NumPart = StringStripWS(String($Number), 8) ; Position of decimal place 0 if none. Local $DecimalPlace = StringInStr($NumPart, ".") ; Split $Number to $NumPart.$DecPart If $DecimalPlace > 0 Then $DecPart = StringLeft(StringMid($NumPart, $DecimalPlace + 1) & "00", 2) $NumPart = StringLeft($NumPart, $DecimalPlace - 1) EndIf Local $Result, $Sum = 0 ;look for Trillions Local $Trillions = Int($NumPart / (1000 * 1000 * 1000 * 1000)) If $Trillions > 0 Then $Result &= DigitGroup($Trillions) & " Trillion " EndIf $Sum += $Trillions * (1000 * 1000 * 1000 * 1000) ;look for Billions Local $Billions = Int(($NumPart - $Sum) / (1000 * 1000 * 1000)) If $Billions > 0 Then $Result &= DigitGroup($Billions) & " Billion " EndIf $Sum += $Billions * (1000 * 1000 * 1000) ;look for Millions Local $Millions = Int(($NumPart - $Sum) / (1000 * 1000)) If $Millions > 0 Then $Result &= DigitGroup($Millions) & " Million " EndIf $Sum += $Millions * (1000 * 1000) ;look for Thousands Local $Thousands = Int(($NumPart - $Sum) / 1000) If $Thousands > 0 Then $Result &= DigitGroup($Thousands) & " Thousand " EndIf $Sum += $Thousands * 1000 ;look for Hundreds Local $Hundreds = Int($NumPart - $Sum) If $Hundreds > 0 Then $Result &= DigitGroup($Hundreds) & " Euro" EndIf ;$Sum += $Hundreds If $Result Then ;look for Decimal Part Switch $DecPart Case "" $Result &= " and No Cents" Case 1 $Result &= " and One Cent" Case Else $Result &= " and " & DigitGroup($DecPart) & " Cents" EndSwitch $Result = StringStripWS($Result, 1 + 2 + 4) Return $Result Else $Result = "No Euros and No Cents" Return SetError(1, 0, $Result) ; Return the $Result and set @error to 1. EndIf EndFunc ;==>N2T_en ;---------------------------------------------------------------------------------------- Func DigitGroup($Value) Local $Hundreds, $Tens, $Ones, $Tens1 = 0 Local $Result, $Sum = 0 ;Do hundreds $Hundreds = Int($Value / 100) Switch $Hundreds Case 0 $Result = "" Case 1 $Result = "One hundred " Case 2 $Result = "two hundred " Case 3 $Result = "Three hundred " Case 4 $Result = "Four hundred " Case 5 $Result = "Five hundred " Case 6 $Result = "Six hundred " Case 7 $Result = "Seven hundred " Case 8 $Result = "Eight hundred " Case 9 $Result = "Nine hundred " EndSwitch $Sum += $Hundreds * 100 ; Do tens (except teens) $Tens = Int(($Value - $Sum) / 10) Switch $Tens Case 1 $Tens1 = 10 ; * (except teens) Case 2 $Result = $Result & "Twenty " Case 3 $Result = $Result & "Thirty " Case 4 $Result = $Result & "Forty " Case 5 $Result = $Result & "Fifty " Case 6 $Result = $Result & "Sixty " Case 7 $Result = $Result & "Seventy " Case 8 $Result = $Result & "Eighty " Case 9 $Result = $Result & "Ninety " EndSwitch $Sum += ($Tens * 10) - $Tens1 ;Do ones and teens $Ones = Int($Value - $Sum) Switch $Ones Case 1 $Result = $Result & "One" Case 2 $Result = $Result & "Two" Case 3 $Result = $Result & "Three" Case 4 $Result = $Result & "Four" Case 5 $Result = $Result & "Five" Case 6 $Result = $Result & "Six" Case 7 $Result = $Result & "Seven" Case 8 $Result = $Result & "Eight" Case 9 $Result = $Result & "Nine" Case 10 $Result = $Result & "Ten" Case 11 $Result = $Result & "Eleven" Case 12 $Result = $Result & "Twelve" Case 13 $Result = $Result & "Thirteen" Case 14 $Result = $Result & "Fourteenth" Case 15 $Result = $Result & "Fifteen" Case 16 $Result = $Result & "Sixteen" Case 17 $Result = $Result & "Seventeen" Case 18 $Result = $Result & "Eighteen" Case 19 $Result = $Result & "Nineteen" EndSwitch Return $Result EndFunc ;==>DigitGroup ;---------------------------------------------------------------------------------------- Edited August 1, 2023 by ioa747 Correction I know that I know nothing Link to comment Share on other sites More sharing options...
AZJIO Posted August 9, 2023 Share Posted August 9, 2023 http://forum.oszone.net/post-1907424.html#post1907424 http://azjio.narod.ru/autoit3_docs/userfunctions/_NumberNumToName.htm https://www.autoitscript.com/forum/topic/142799-converting-numbers ioa747 1 My other projects or all Link to comment Share on other sites More sharing options...
ioa747 Posted February 24 Author Share Posted February 24 RegExp approach I know that I know nothing Link to comment Share on other sites More sharing options...
Moderators SmOke_N Posted February 24 Moderators Share Posted February 24 5 minutes ago, ioa747 said: RegExp approach Ha, I never bothered searching the forum for an already done example (I see there were a few now)... I was just annoyed when I did mine! 😂 ioa747 1 Common sense plays a role in the basics of understanding AutoIt... If you're lacking in that, do us all a favor, and step away from the computer. Link to comment Share on other sites More sharing options...
ioa747 Posted February 24 Author Share Posted February 24 in Greek language expandcollapse popup; https://www.autoitscript.com/forum/topic/210620-spellnumber-function-to-convert-numbers-to-words ;---------------------------------------------------------------------------------------- ; Title...........: SpellNumber.au3 ; Description.....: Convert numbers into words - Greek ; AutoIt Version..: 3.3.16.1 Author: ioa747 ; https://support.microsoft.com/en-au/office/convert-numbers-into-words-a0d166fb-e1ea-4090-95c8-69442cd55d98 ;---------------------------------------------------------------------------------------- #AutoIt3Wrapper_Au3Check_Parameters=-d -w 1 -w 2 -w 3 -w 4 -w 5 -w 6 -w 7 ConsoleWrite("" & SpellNumber(1100.25) & @CRLF) ConsoleWrite("" & SpellNumber(105533) & @CRLF) ;---------------------------------------------------------------------------------------- Func SpellNumber($MyNumber) Local $Coin = "ευρό" ; Dollar Local $Units, $SubUnits, $Temp Local $DecimalPlace, $Count Local $Place[9] $Place[2] = " χίλια " $Place[3] = " εκατομμύριο " $Place[4] = " δισεκατομμύριο " $Place[5] = " τρισεκατομμύριο " ; String representation of amount. $MyNumber = StringStripWS(String($MyNumber), 8) ; Position of decimal place 0 if none. $DecimalPlace = StringInStr($MyNumber, ".") ; Convert $SubUnits and set $MyNumber to dollar amount. If $DecimalPlace > 0 Then $SubUnits = GetTens(StringLeft(StringMid($MyNumber, $DecimalPlace + 1) & "00", 2)) $MyNumber = StringStripWS(StringLeft($MyNumber, $DecimalPlace - 1), 8) EndIf $Count = 1 While $MyNumber <> "" $Temp = GetHundreds(StringRight($MyNumber, 3)) If $Temp <> "" Then $Units = $Temp & $Place[$Count] & $Units If StringLen($MyNumber) > 3 Then $MyNumber = StringLeft($MyNumber, StringLen($MyNumber) - 3) Else $MyNumber = "" EndIf $Count = $Count + 1 WEnd Switch $Units Case "" $Units = "ακριβώς " Case "ένα" $Units = "ένα " & $Coin Case Else $Units = $Units & " λεπτά" EndSwitch Switch $SubUnits Case "" $SubUnits = " ακριβώς" Case "ένα" $SubUnits = " και ένα λεπτό" Case Else $SubUnits = " και " & $SubUnits & " λεπτά" EndSwitch Local $Result = StringStripWS($Units & $SubUnits, 1 + 2 + 4) $Result = StringReplace($Result, "ένα εκατό", "εκατόν") $Result = StringReplace($Result, "ένα χίλια", "χίλια") Return $Result EndFunc ;==>SpellNumber ;---------------------------------------------------------------------------------------- Func GetHundreds($MyNumber) ; Converts a number from 100-999 into text Local $Result If Int($MyNumber) = 0 Then Return $MyNumber = StringRight("000" & $MyNumber, 3) ; Convert the hundreds place. If StringMid($MyNumber, 1, 1) <> "0" Then $Result = GetDigit(StringMid($MyNumber, 1, 1)) & " εκατό " EndIf ; Convert the tens and ones place. If StringMid($MyNumber, 2, 1) <> "0" Then $Result = $Result & GetTens(StringMid($MyNumber, 2)) Else $Result = $Result & GetDigit(StringMid($MyNumber, 3)) EndIf Return $Result EndFunc ;==>GetHundreds ;---------------------------------------------------------------------------------------- Func GetTens($TensText) ; Converts a number from 10 to 99 into text. Local $Result = "" ; Null out the $Temporary function value. If Int(StringLeft($TensText, 1)) = 1 Then ; If value between 10-19... Switch Int($TensText) Case 10 $Result = "δέκα" Case 11 $Result = "ένδεκα" Case 12 $Result = "δώδεκα" Case 13 $Result = "δεκατρία" Case 14 $Result = "δεκατέσσερα" Case 15 $Result = "δεκαπέντε" Case 16 $Result = "δεκαέξι" Case 17 $Result = "δεκαεπτά" Case 18 $Result = "δεκαοχτώ" Case 19 $Result = "δεκαεννέα" Case Else EndSwitch Else ; If value between 20-99... Switch Int(StringLeft($TensText, 1)) Case 2 $Result = "είκοσι " Case 3 $Result = "τριάντα " Case 4 $Result = "σαράντα " Case 5 $Result = "πενήντα " Case 6 $Result = "εξήντα " Case 7 $Result = "εβδομήντα " Case 8 $Result = "ογδόντα " Case 9 $Result = "εννενήντα " Case Else EndSwitch $Result = $Result & GetDigit(StringRight($TensText, 1)) ; Retrieve ones place. EndIf Return $Result EndFunc ;==>GetTens ;---------------------------------------------------------------------------------------- Func GetDigit($Digit) ; Converts a number from 1 to 9 into text. Local $Result Switch Int($Digit) Case 1 $Result = "ένα" Case 2 $Result = "δύο" Case 3 $Result = "τρία" Case 4 $Result = "τέσσερα" Case 5 $Result = "πέντε" Case 6 $Result = "εξι" Case 7 $Result = "επτά" Case 8 $Result = "οκτώ" Case 9 $Result = "ενέα" Case Else $Result = "" EndSwitch Return $Result EndFunc ;==>GetDigit ;---------------------------------------------------------------------------------------- argumentum 1 I know that I know nothing Link to comment Share on other sites More sharing options...
AspirinJunkie Posted February 25 Share Posted February 25 To add a little more to the story - here is the German version: expandcollapse popupConsoleWrite(_TextNumberGerman("-145323523001267.456") & @CRLF) Func _TextNumberGerman($nZahl, $iNachkommastellen = Default) Local $aSingular[8] = ["s", "tausend", "e Million", "e Milliarde", "e Billion", "e Billiarde", "e Trillion", "e Trilliarde"] Local $aPlural[8] = ["", "tausend", " Millionen", " Milliarden", " Billionen", " Billiarden", " Trillionen", " Trilliarden"] Local $aNullEins[8] = ["s", "stausend", "s Millionen", "s Milliarden", "s Billionen", "s Billiarden", "s Trillionen", "s Trilliarden"] Local $aKleiner20[19] = ["ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn"] Local $aZehner[8] = ["zwanzig", "dreißig", "vierzig", "fünzig", "sechzig", "siebzig", "achtzig", "neunzig"] Local $aDezimal[10] = ["null", "eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun"] Local $sRet = "" ; konvertiere in string $nZahl = IsKeyword($iNachkommastellen) = 1 ? String($nZahl) : StringFormat("%." & $iNachkommastellen & "f", $nZahl) ; negative Zahlen If StringLeft($nZahl, 1) = "-" Then $nZahl = StringTrimLeft($nZahl, 1) $sRet = "Minus " EndIf Local $iGanz = StringInStr($nZahl, '.', 1) ? StringLeft($nZahl, StringInStr($nZahl, ".", 1)) : $nZahl Local $n = StringLen($iGanz), $h, $r, $z, $e Local $aGruppen[Ceiling($n / 3)] Local $sDezimal = StringInStr($nZahl, '.', 1) ? StringTrimLeft($nZahl, StringInStr($nZahl, ".", 1)) : "" Local $i = -1 While $iGanz > 0 ; iGanz in Dreiergruppen teilen: $i += 1 $aGruppen[$i] = Mod($iGanz, 1000) $iGanz = Int($iGanz / 1000) WEnd ; Ganzzahlanteil Local $h, $r, $z, $e While $i >= 0 If $aGruppen[$i] > 0 Then $h = Int($aGruppen[$i] / 100) $r = Mod($aGruppen[$i], 100) $z = Int($r / 10) $e = Mod($aGruppen[$i], 10) If $h > 0 Then $sRet &= $aKleiner20[$h - 1] & "hundert" If $r > 0 Then If $r < 20 Then $sRet &= $aKleiner20[$r - 1] Else If $e > 0 Then $sRet &= $aKleiner20[$e - 1] If $e > 0 And $z > 0 Then $sRet &= "und" If $z > 0 Then $sRet &= $aZehner[$z - 2] EndIf EndIf If $aGruppen[$i] = 1 Then $sRet &= $aSingular[$i] & " " ElseIf StringRight($aGruppen[$i], 2) = "01" Then $sRet &= $aNullEins[$i] & " " Else $sRet &= $aPlural[$i] & " " EndIf EndIf $i -= 1 WEnd $sRet = StringStripWS($sRet, 2) ; Dezimalteil If $sDezimal <> "" Then $sRet &= " Komma" For $sZiffer in StringSplit($sDezimal, "", 2) $sRet &= " " & $aDezimal[Int($sZiffer)] Next EndIf Return $sRet EndFunc ;==>_TextNumberGerman ioa747 1 Link to comment Share on other sites More sharing options...
LAteNightSpecial Posted February 26 Share Posted February 26 16 hours ago, AspirinJunkie said: To add a little more to the story - here is the German version: expandcollapse popupConsoleWrite(_TextNumberGerman("-145323523001267.456") & @CRLF) Func _TextNumberGerman($nZahl, $iNachkommastellen = Default) Local $aSingular[8] = ["s", "tausend", "e Million", "e Milliarde", "e Billion", "e Billiarde", "e Trillion", "e Trilliarde"] Local $aPlural[8] = ["", "tausend", " Millionen", " Milliarden", " Billionen", " Billiarden", " Trillionen", " Trilliarden"] Local $aNullEins[8] = ["s", "stausend", "s Millionen", "s Milliarden", "s Billionen", "s Billiarden", "s Trillionen", "s Trilliarden"] Local $aKleiner20[19] = ["ein", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun", "zehn", "elf", "zwölf", "dreizehn", "vierzehn", "fünfzehn", "sechzehn", "siebzehn", "achtzehn", "neunzehn"] Local $aZehner[8] = ["zwanzig", "dreißig", "vierzig", "fünzig", "sechzig", "siebzig", "achtzig", "neunzig"] Local $aDezimal[10] = ["null", "eins", "zwei", "drei", "vier", "fünf", "sechs", "sieben", "acht", "neun"] Local $sRet = "" ; konvertiere in string $nZahl = IsKeyword($iNachkommastellen) = 1 ? String($nZahl) : StringFormat("%." & $iNachkommastellen & "f", $nZahl) ; negative Zahlen If StringLeft($nZahl, 1) = "-" Then $nZahl = StringTrimLeft($nZahl, 1) $sRet = "Minus " EndIf Local $iGanz = StringInStr($nZahl, '.', 1) ? StringLeft($nZahl, StringInStr($nZahl, ".", 1)) : $nZahl Local $n = StringLen($iGanz), $h, $r, $z, $e Local $aGruppen[Ceiling($n / 3)] Local $sDezimal = StringInStr($nZahl, '.', 1) ? StringTrimLeft($nZahl, StringInStr($nZahl, ".", 1)) : "" Local $i = -1 While $iGanz > 0 ; iGanz in Dreiergruppen teilen: $i += 1 $aGruppen[$i] = Mod($iGanz, 1000) $iGanz = Int($iGanz / 1000) WEnd ; Ganzzahlanteil Local $h, $r, $z, $e While $i >= 0 If $aGruppen[$i] > 0 Then $h = Int($aGruppen[$i] / 100) $r = Mod($aGruppen[$i], 100) $z = Int($r / 10) $e = Mod($aGruppen[$i], 10) If $h > 0 Then $sRet &= $aKleiner20[$h - 1] & "hundert" If $r > 0 Then If $r < 20 Then $sRet &= $aKleiner20[$r - 1] Else If $e > 0 Then $sRet &= $aKleiner20[$e - 1] If $e > 0 And $z > 0 Then $sRet &= "und" If $z > 0 Then $sRet &= $aZehner[$z - 2] EndIf EndIf If $aGruppen[$i] = 1 Then $sRet &= $aSingular[$i] & " " ElseIf StringRight($aGruppen[$i], 2) = "01" Then $sRet &= $aNullEins[$i] & " " Else $sRet &= $aPlural[$i] & " " EndIf EndIf $i -= 1 WEnd $sRet = StringStripWS($sRet, 2) ; Dezimalteil If $sDezimal <> "" Then $sRet &= " Komma" For $sZiffer in StringSplit($sDezimal, "", 2) $sRet &= " " & $aDezimal[Int($sZiffer)] Next EndIf Return $sRet EndFunc ;==>_TextNumberGerman 😇 Who doesn't love a good story that they did not write but took the time to read 16 pages of. expandcollapse popupConsoleWrite(_TextNumerusGermanicus("-145323523001267.456") & @CRLF) Func _TextNumerusGermanicus($nNumerus, $iDecimalibus = Default) Local $aSingularis[8] = ["s", "mille", "Millio", "Milliardo", "Billiones", "Billiardes", "Trilliones", "Trilliardes"] Local $aPluralis[8] = ["", "mille", "Milliones", "Milliardes", "Billiones", "Billiardes", "Trilliones", "Trilliardes"] Local $aNullEins[8] = ["s", "mille", "Milliones", "Milliardes", "Billiones", "Billiardes", "Trilliones", "Trilliardes"] Local $aMinusculi[19] = ["unus", "duo", "tres", "quattuor", "quinque", "sex", "septem", "octo", "novem", "decem", "undecim", "duodecim", "tredecim", "quattuordecim", "quindecim", "sedecim", "septendecim", "duodeviginti", "novendecim"] Local $aDecem[8] = ["viginti", "triginta", "quadraginta", "quinquaginta", "sexaginta", "septuaginta", "octoginta", "nonaginta"] Local $aDecimalis[10] = ["nulla", "una", "duo", "tres", "quattuor", "quinque", "sex", "septem", "octo", "novem"] Local $sRet = "" ; Convertitur ad string $nNumerus = IsKeyword($iDecimalibus) = 1 ? String($nNumerus) : StringFormat("%." & $iDecimalibus & "f", $nNumerus) ; Numeri negativi If StringLeft($nNumerus, 1) = "-" Then $nNumerus = StringTrimLeft($nNumerus, 1) $sRet = "Minus " EndIf Local $iInteger = StringInStr($nNumerus, '.', 1) ? StringLeft($nNumerus, StringInStr($nNumerus, ".", 1)) : $nNumerus Local $n = StringLen($iInteger), $h, $r, $z, $e Local $aGruppi[Ceiling($n / 3)] Local $sDecimalis = StringInStr($nNumerus, '.', 1) ? StringTrimLeft($nNumerus, StringInStr($nNumerus, ".", 1)) : "" Local $i = -1 While $iInteger > 0 ; Divide integer in gruppis de tribus: $i += 1 $aGruppi[$i] = Mod($iInteger, 1000) $iInteger = Int($iInteger / 1000) WEnd ; Partis integer Local $h, $r, $z, $e While $i >= 0 If $aGruppi[$i] > 0 Then $h = Int($aGruppi[$i] / 100) $r = Mod($aGruppi[$i], 100) $z = Int($r / 10) $e = Mod($aGruppi[$i], 10) If $h > 0 Then $sRet &= $aMinusculi[$h - 1] & "centum" If $r > 0 Then If $r < 20 Then $sRet &= $aMinusculi[$r - 1] Else If $e > 0 Then $sRet &= $aMinusculi[$e - 1] If $e > 0 And $z > 0 Then $sRet &= "et" If $z > 0 Then $sRet &= $aDecem[$z - 2] EndIf EndIf If $aGruppi[$i] = 1 Then $sRet &= $aSingularis[$i] & " " ElseIf StringRight($aGruppi[$i], 2) = "01" Then $sRet &= $aNullEins[$i] & " " Else $sRet &= $aPluralis[$i] & " " EndIf EndIf $i -= 1 WEnd $sRet = StringStripWS($sRet, 2) ; Partis decimalis If $sDecimalis <> "" Then $sRet &= " Virgula" For $sDigitus in StringSplit($sDecimalis, "", 2) $sRet &= " " & $aDecimalis[Int($sDigitus)] Next EndIf Return $sRet EndFunc ;==>_TextNumerusGermanicus ioa747 1 Link to comment Share on other sites More sharing options...
Recommended Posts
Create an account or sign in to comment
You need to be a member in order to leave a comment
Create an account
Sign up for a new account in our community. It's easy!
Register a new accountSign in
Already have an account? Sign in here.
Sign In Now