Jump to content

IntToWord


Recommended Posts

I started to write a function for that at one time and never did complete it. Pretty simple up to the thousands. There are several javascript versions of it available by usinggoogle. just search for it and then convert that code to AutoIt.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

  • Developers

i need Int To Word

like in vb6 WordFromInterger

show an example scriptlet where this is needed so we can understand.

SciTE4AutoIt3 Full installer Download page   - Beta files       Read before posting     How to post scriptsource   Forum etiquette  Forum Rules 
 
Live for the present,
Dream of the future,
Learn from the past.
  :)

Link to comment
Share on other sites

I think he wants a numerical to return the string representation. 100 returns "one hundred", 10 returns "ten" etc. I was writing an app for printing cheques when I last played with that. He knows the VBS function for it but js has no such function. That's why I suggested he look up the js code snippets that are all over the place and do a conversion.

George

Question about decompiling code? Read the decompiling FAQ and don't bother posting the question in the forums.

Be sure to read and follow the forum rules. -AKA the AutoIt Reading and Comprehension Skills test.***

The PCRE (Regular Expression) ToolKit for AutoIT - (Updated Oct 20, 2011 ver:3.0.1.13) - Please update your current version before filing any bug reports. The installer now includes both 32 and 64 bit versions. No change in version number.

Visit my Blog .. currently not active but it will soon be resplendent with news and views. Also please remove any links you may have to my website. it is soon to be closed and replaced with something else.

"Old age and treachery will always overcome youth and skill!"

Link to comment
Share on other sites

Probably slightly out... Uses short scale only as it's easy.

Local $iNum = 123456789876543
MsgBox(0, $iNum, NumToWord($iNum))

Func NumToWord($iNum)
    Local $asDigits[10] = ["zero", "one", "two", "three", "four", "five", "six", "seven", "eight", "nine"]
    Local $asTeens[8] = ["eleven", "twelve", "thirteen", "fourteen", "fifteen", "sixteen", "seventeen", "nineteen"]
    Local $asTens[9] = ["ten", "twenty", "thirty", "forty", "fifty", "sixty", "seventy", "eighty", "ninety"]
    Local $asBig[22] = ["thousand", "million", "billion", "trillion", "quadrillion", "quintillion", "sextillion", "septillion", "octillion", "nonillion", _
                        "decillion", "undecillion", "duodecillion", "tredecillion", "quattuordecillion", "quindecillion", "sexdecillion", "septendecillion", "octodecillion", "novemdecillion", "vigintillion"]

    Local $sRet = ""

    ; Very big numbers
    For $i = 22 To 1 Step - 1
        If $iNum >= 10 ^ ($i * 3) Then
            $iTemp = Floor($iNum / (10 ^ ($i * 3)))
            $iNum -= $iTemp * (10 ^ ($i * 3))
            $sRet &= NumToWord($iTemp) & " " & $asBig[$i - 1] & " "
        EndIf
    Next

    ; hundreds
    If $iNum >= 100 Then
        $iTemp = Floor($iNum / 100)
        $iNum -= $iTemp * 100
        $sRet &= NumToWord($iTemp) & " hundred and "
    EndIf

    If $iNum > 10 And $iNum < 20 Then
        $iTemp = Floor($iNum - 11)
        $iNum -= 11 + $iTemp
        $sRet &= $asTeens[$iTemp] & " "
    Else
        ; Tens
        If $iNum >= 10 Then
            $iTemp = Floor($iNum / 10)
            $iNum -= $iTemp * 10
            $sRet &= $asTens[$iTemp - 1] & " "
        EndIf

        ; Digits
        If $iNum >= 1 Then
            $sRet &= $asDigits[Floor($iNum)] & " "
            $iNum -= Floor($iNum)
        EndIf
    EndIf

    Return $sRet
EndFunc
Edited by Mat
Link to comment
Share on other sites

i solved this with my udf :blink:

here is code

Func WordFromInteger($data)     
$WordFromInteger = Hex($data)   
If StringLen($WordFromInteger) = 1 Then         
$WordFromInteger = "0" & $WordFromInteger & "00"     
ElseIf StringLen($WordFromInteger) = 2 Then         
$WordFromInteger = $WordFromInteger & "00"     
ElseIf StringLen($WordFromInteger) = 3 Then         
$WordFromInteger = StringMid($WordFromInteger, 2, 2) & "0" & StringLeft($WordFromInteger, 1)    
ElseIf StringLen($WordFromInteger) = 4 Then         
$WordFromInteger = StringMid($WordFromInteger, 3, 2) & StringLeft($WordFromInteger, 2)     
EndIf   
Return $WordFromInteger     
EndFunc
Link to comment
Share on other sites

i solved this with my udf ;)

here is code

Func WordFromInteger($data)     
$WordFromInteger = Hex($data)   
If StringLen($WordFromInteger) = 1 Then         
$WordFromInteger = "0" & $WordFromInteger & "00"     
ElseIf StringLen($WordFromInteger) = 2 Then         
$WordFromInteger = $WordFromInteger & "00"     
ElseIf StringLen($WordFromInteger) = 3 Then         
$WordFromInteger = StringMid($WordFromInteger, 2, 2) & "0" & StringLeft($WordFromInteger, 1)    
ElseIf StringLen($WordFromInteger) = 4 Then         
$WordFromInteger = StringMid($WordFromInteger, 3, 2) & StringLeft($WordFromInteger, 2)     
EndIf   
Return $WordFromInteger     
EndFunc

Congratulation, awesome UDF!

:blink:

Edited by Yashied
Link to comment
Share on other sites

And there I was writing a big UDF to turn numbers into english words... :blink:

Func WordFromInteger($data)
    Return Hex($data, 8)
EndFunc

And heres my updated NumToWord. It now works well and does decimals.

link

You will here a lot of people on the next page complaining at how the function that was until just now posted here didn't work and I admit I left out a possibly important number by mistake. The one there works.

Edited by Mat
Link to comment
Share on other sites

For those that like to extend NumToWord($iNum) to include "long scale" output.

http://en.wikipedia.org/wiki/Names_of_large_numbers#Extensions_of_the_standard_dictionary_numbers

(Org Example topic: NumToWord As in 100 = One hundred... *human* words...)

Edited by MvGulik

"Straight_and_Crooked_Thinking" : A "classic guide to ferreting out untruths, half-truths, and other distortions of facts in political and social discussions."
"The Secrets of Quantum Physics" : New and excellent 2 part documentary on Quantum Physics by Jim Al-Khalili. (Dec 2014)

"Believing what you know ain't so" ...

Knock Knock ...
 

Link to comment
Share on other sites

  • 2 months later...

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 account

Sign in

Already have an account? Sign in here.

Sign In Now
 Share

  • Recently Browsing   0 members

    • No registered users viewing this page.
×
×
  • Create New...