Author Topic: Convert numbers to words. Function from Lee Mac. Question...  (Read 2327 times)

0 Members and 1 Guest are viewing this topic.

Dilan

  • Newt
  • Posts: 23
Convert numbers to words. Function from Lee Mac. Question...
« on: December 15, 2018, 12:02:42 AM »
Hello everyone. I found this code in the forum:
Code: [Select]
(defun LM:int->words ( n / f1 f2 )
    (defun f1 ( n )
        (if (< n 20)
            (nth (fix n) '("" "one" "two" "three" "four" "five" "six" "seven" "eight" "nine" "ten" "eleven" "twelve" "thirteen" "fourteen" "fifteen" "sixteen" "seventeen" "eighteen" "nineteen"))
            (strcat (nth (- (fix (/ n 10)) 2) '("twenty" "thirty" "forty" "fifty" "sixty" "seventy" "eighty" "ninety")) " " (f1 (rem n 10)))
        )
    )
    (defun f2 ( n l )
        (cond
            (   (null l) (f1 n))
            (   (< n (caar l)) (f2 n (cdr l)))
            (   (vl-string-right-trim " " (strcat (f2 (fix (/ n (caar l))) (cdr l)) " " (cadar l) " " (f2 (rem n (caar l)) (cdr l)))))
        )
    )
    (if (zerop n)
        "zero"
        (vl-string-right-trim " "
            (f2 n
               '(
                    (1e18 "quintillion")
                    (1e15 "quadrillion")
                    (1e12 "trillion")
                    (1e09 "billion")
                    (1e06 "million")
                    (1e03 "thousand")
                    (1e02 "hundred")
                )
            )
        )
    )
)
Tell me who knows how to make words-> int.
For example:
From "twenty one thousand five hundred thirty seven" in 21537

PKENEWELL

  • Bull Frog
  • Posts: 318
"When you are asked if you can do a job, tell 'em, 'Certainly I can!' Then get busy and find out how to do it." - Theodore Roosevelt


Gergeobusges

  • Guest
Re: Convert numbers to words. Function from Lee Mac. Question...
« Reply #3 on: December 21, 2018, 12:22:15 AM »
If I want to know more about this. What should I do Please tell me.

kdub_nz

  • Mesozoic keyThumper
  • SuperMod
  • Water Moccasin
  • Posts: 2139
  • class keyThumper<T>:ILazy<T>
Re: Convert numbers to words. Function from Lee Mac. Question...
« Reply #4 on: December 21, 2018, 03:16:17 AM »
If I want to know more about this. What should I do Please tell me.

George, with all due respect : you should study for a couple of years and appempt to write a lot of code, every day.

Regards,
Called Kerry in my other life
Retired; but they dragged me back in !

I live at UTC + 13.00

---
some people complain about loading the dishwasher.
Sometimes the question is more important than the answer.