factor out money>string

db4
Doug Coleman 2008-09-06 13:58:14 -05:00
parent dbab0b633e
commit 0589e061e1
1 changed files with 6 additions and 4 deletions

View File

@ -6,14 +6,16 @@ IN: money
: dollars/cents ( dollars -- dollars cents ) : dollars/cents ( dollars -- dollars cents )
100 * 100 /mod round ; 100 * 100 /mod round ;
: money. ( object -- ) : money>string ( object -- string )
dollars/cents dollars/cents [
[
"$" % "$" %
swap number>string swap number>string
<reversed> 3 group "," join <reversed> % <reversed> 3 group "," join <reversed> %
"." % number>string 2 CHAR: 0 pad-left % "." % number>string 2 CHAR: 0 pad-left %
] "" make print ; ] "" make ;
: money. ( object -- )
money>string print ;
ERROR: not-a-decimal x ; ERROR: not-a-decimal x ;