REBOL 3 Docs Guide Concepts Functions Datatypes Errors
  TOC < Back Next >   Updated: 6-Feb-2009 Edit History  

REBOL 3 Datatypes: Money!



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.


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
probe $1'234'567,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
probe second my-money
probe pick my-money 3       ; only two components

If no currency designator is used, the currency designator string is empty:

my-money: $12345.67

probe first my-money
probe second my-money

Various international currencies can be specified in the currency designator, such as:

my-money: DKM$12'345,67

probe first my-money
probe second my-money


Use the to-money function to convert money from a string!, integer!, decimal!, or block!.

probe to-money 123
probe to-money "123"
probe to-money 12.34
probe to-money [DEM 12.34]
probe to-money [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
probe $100 - $50
probe equal? DEM$100.11 DEM$100.11

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
probe $100 / 4
probe $100 * 5
probe $100 - 20.50
probe 10 + $1.20
probe 10 - $0.25
probe $10 / .50
probe 10 * $0.75


Use money? to determine whether a value is an money! datatype.

probe money? USD$12.34

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
probe mold USD$12.34
print USD$12.34

  TOC < Back Next > - WIP Wiki Feedback Admin