Check printer - Convert to English text from the input value.

3

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.

CW Holeman II

Posted 2011-03-07T06:52:50.100

Reputation: 131

2can we assume that answers could be in codegolf way? – YOU – 2011-03-07T06:58:26.207

Is this a function or a whole program? – gnibbler – 2011-03-07T12:11:19.020

Hm... I did this once for MMIX... Wait some time and I change it to satisfy the conditions. That's fun! – FUZxxl – 2011-03-07T13:58:13.783

1How should 12.00 be written? "twelve dollars" or "twelve dollars and xx/00" or something? – Joey Adams – 2011-03-08T01:02:42.547

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.

– dmckee --- ex-moderator kitten – 2011-03-11T19:35:47.340

Answers

3

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"

J B

Posted 2011-03-07T06:52:50.100

Reputation: 9 638