Guest User

Untitled

a guest
Apr 12th, 2018
129
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
  1. Integer>>asWords
  2.  
  3. asWords
  4.     "SmallInteger maxVal asWords"
  5.     | mils minus three num answer milCount |
  6.     self = 0 ifTrue: [^'zero'].
  7.     mils := #('' ' thousand' ' million' ' billion' ' trillion' ' quadrillion' ' quintillion' ' sextillion' ' septillion' ' octillion' ' nonillion' ' decillion' ' undecillion' ' duodecillion' ' tredecillion' ' quattuordecillion' ' quindecillion' ' sexdecillion' ' septendecillion' ' octodecillion' ' novemdecillion' ' vigintillion' ' unvigintillion' ' duovigintillion' ' trevigintillion' ' quattuorvigintillion' ' quinvigintillion' ' sexvigintillion' ' septenvigintillion' ' octovigintillion' ' novemvigintillion' ' trigintillion' ' untrigintillion' ' duotrigintillion').
  8.     num := self.
  9.     minus := ''.
  10.     self < 0 ifTrue: [
  11.         minus := 'negative '.
  12.         num := num negated.
  13.     ].
  14.     answer := String new.
  15.     milCount := 1.
  16.     [num > 0] whileTrue: [
  17.         three := (num \\ 1000) threeDigitName.
  18.         num := num // 1000.
  19.         three isEmpty ifFalse: [
  20.             answer isEmpty ifFalse: [
  21.                 answer := ', ',answer
  22.             ].
  23.             answer := three,(mils at: milCount),answer.
  24.         ].
  25.         milCount := milCount + 1.
  26.     ].
  27.     ^minus,answer
Add Comment
Please, Sign In to add comment