money: adding support for floats.

char-rename
John Benediktsson 2017-01-25 16:44:25 -08:00
parent b93aa90486
commit 9a34af7381
2 changed files with 6 additions and 1 deletions

View File

@ -23,3 +23,8 @@ IN: money.tests
{ "$100.00" } [ DECIMAL: 100.0 money>string ] unit-test { "$100.00" } [ DECIMAL: 100.0 money>string ] unit-test
{ "$0.00" } [ DECIMAL: 0.0 money>string ] unit-test { "$0.00" } [ DECIMAL: 0.0 money>string ] unit-test
{ "$1.00" } [ 1.0 money>string ] unit-test
{ "$1.00" } [ 1 money>string ] unit-test
{ "$1.50" } [ 1+1/2 money>string ] unit-test
{ "$1.50" } [ 1.50 money>string ] unit-test

View File

@ -8,7 +8,7 @@ SYMBOL: currency-token
CHAR: $ currency-token set-global CHAR: $ currency-token set-global
: dollars/cents ( dollars -- dollars cents ) : dollars/cents ( dollars -- dollars cents )
100 * 100 /mod round ; 100 * 100 /mod round >integer ;
: format-money ( dollars cents -- string ) : format-money ( dollars cents -- string )
[ number>string ] bi@ [ number>string ] bi@