Check printer function (or subroutine) - Convert to English text from the input value. 12.34 -> "twelve dollars and thirty four cents". For the range .01 to 9999.99 assuming valid input.

  • 2
    \$\begingroup\$ can we assume that answers could be in codegolf way? \$\endgroup\$ – YOU Mar 7 '11 at 6:58
  • \$\begingroup\$ Is this a function or a whole program? \$\endgroup\$ – gnibbler Mar 7 '11 at 12:11
  • \$\begingroup\$ Hm... I did this once for MMIX... Wait some time and I change it to satisfy the conditions. That's fun! \$\endgroup\$ – FUZxxl Mar 7 '11 at 13:58
  • 1
    \$\begingroup\$ How should 12.00 be written? "twelve dollars" or "twelve dollars and xx/00" or something? \$\endgroup\$ – Joey Adams Mar 8 '11 at 1:02
  • \$\begingroup\$ You are generally expected to tag questions with a type-of-puzzle tag (so far code-golf or code-challenge). Please correct my edit if I chose poorly. \$\endgroup\$ – dmckee --- ex-moderator kitten Mar 11 '11 at 19:35

Common Lisp, 95

Newline not counted in:

(lambda(n &aux(d(floor n))(c(round(*(- n d)100))))
(format()"~R dollar~P and ~R cent~P"d d c c))

Sample use (assigning it to f):

CL-USER> (f .01)
"zero dollars and one cent"
CL-USER> (f 12.34)
"twelve dollars and thirty-four cents"
CL-USER> (f 9999.99)
"nine thousand nine hundred ninety-nine dollars and ninety-nine cents"

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.