REBOL 3 Docs | Guide | Concepts | Functions | Datatypes | Errors |
TOC < Back Next > | Updated: 6-Feb-2009 Edit History |
There is a wide variety of international symbols for monetary denominations. Some symbols are used before the amount and some after. As a standard for representing international monetary values, the REBOL language uses the United States monetary format, but allows the inclusion of specific denominations.
The money! datatype uses standard IEEE floating point numbers allowing up to 15 digits of precision including cents.
The language limits the length to 64 characters. Values that are out of range or cannot be represented in 64 characters are flagged as an error.
Monetary values are prefixed with an optional currency designator, followed by a dollar sign ($). A plus (+) or minus (-) can appear immediately before the first character (currency designator or dollar sign) to indicate sign.
$123 -$123 $123.45 US$12 US$12.34 -US$12.34 $12,34 -$12,34 DEM$12,34
To break long numbers into readable segments, a single quote (`) can be placed anywhere between two digits within the amount, but not before the amount.
probe $1'234.56
$1234.56
probe $1'234'567,89
$1234567.89
Do not use commas and periods to break up large amounts, as both these characters represent decimal points.
'The money! datatype is a hybrid datatype. Conceptually money is scalar--an amount of money. However, because the currency designation is stored as a string, the money! datatype has two elements:
To demonstrate this, the following money is specified with the USD prefix:
my-money: USD$12345.67
Here are the two components:
probe first my-money
USD
probe second my-money
12345.67
probe pick my-money 3 ; only two components
none
If no currency designator is used, the currency designator string is empty:
my-money: $12345.67
probe first my-money
""
probe second my-money
12345.67
Various international currencies can be specified in the currency designator, such as:
my-money: DKM$12'345,67
probe first my-money
DKM
probe second my-money
12345.67
Use the to-money function to convert money from a string!, integer!, decimal!, or block!.
probe to-money 123
$123.00
probe to-money "123"
$123.00
probe to-money 12.34
$12.34
probe to-money [DEM 12.34]
DEM$12.34
probe to-money [USA 12 34]
USA$12.34
Money can be added, subtracted, and compared with other money of the same currency. An error occurs if a different currency is used for such operations (automatic conversions are not currently supplied).
probe $100 + $10
$110.00
probe $100 - $50
$50.00
probe equal? DEM$100.11 DEM$100.11
true
Money can be multiplied and divided by integers and decimals. Money can also be divided by money, resulting in an integer or decimal.
probe $100 + 11
$111.00
probe $100 / 4
$25.00
probe $100 * 5
$500.00
probe $100 - 20.50
$79.50
probe 10 + $1.20
$11.20
probe 10 - $0.25
$9.75
probe $10 / .50
$20.00
probe 10 * $0.75
$7.50
Use money? to determine whether a value is an money! datatype.
probe money? USD$12.34
true
Use the form, print, and mold functions with a money argument to print a money value with the currency designator and dollar sign ($), as a decimal number with two digits of decimal precision.
probe form USD$12.34
USD$12.34
probe mold USD$12.34
USD$12.34
print USD$12.34
USD$12.34
TOC < Back Next > | REBOL.com - WIP Wiki | Feedback Admin |