cleanup on aisle DECIMAL:
parent
9fe1dd871a
commit
008da8a6ba
|
@ -12,18 +12,21 @@ IN: money
|
||||||
"$" %
|
"$" %
|
||||||
swap number>string
|
swap number>string
|
||||||
<reversed> 3 group "," join <reversed> %
|
<reversed> 3 group "," join <reversed> %
|
||||||
"." % number>string 2 48 pad-left %
|
"." % number>string 2 CHAR: 0 pad-left %
|
||||||
] "" make print ;
|
] "" make print ;
|
||||||
|
|
||||||
TUPLE: not-a-decimal ;
|
TUPLE: not-a-decimal ;
|
||||||
: DECIMAL:
|
|
||||||
scan
|
: not-a-decimal ( -- * )
|
||||||
"." split dup length 1 2 between? [
|
T{ not-a-decimal } throw ;
|
||||||
T{ not-a-decimal } throw
|
|
||||||
] unless
|
: parse-decimal ( str -- ratio )
|
||||||
?first2
|
"." split1
|
||||||
>r dup ?first CHAR: - = [ drop t "0" ] [ f swap ] if r>
|
>r dup "-" head? [ drop t "0" ] [ f swap ] if r>
|
||||||
[ dup empty? [ drop "0" ] when ] 2apply
|
[ dup empty? [ drop "0" ] when ] 2apply
|
||||||
dup length
|
dup length
|
||||||
>r [ string>number dup [ T{ not-a-decimal } throw ] unless ] 2apply r>
|
>r [ string>number dup [ not-a-decimal ] unless ] 2apply r>
|
||||||
10 swap ^ / + swap [ neg ] when parsed ; parsing
|
10 swap ^ / + swap [ neg ] when ;
|
||||||
|
|
||||||
|
: DECIMAL:
|
||||||
|
scan parse-decimal parsed ; parsing
|
||||||
|
|
Loading…
Reference in New Issue