### ToNumber (numeric), ToNumber (string)

Basic and Crystal syntax.

ToNumber and CDbl are equivalent functions.

##### Arguments

- numeric is a Number or a Currency type value.
- string is a text string that holds numeric text.

##### Returns

Fractional Number

##### Action

ToNumber converts a Number, Currency or text string to a Number.

In a database, some numbers are stored in numeric fields, as Numbers, and some are stored in character fields, as text. You make the determination which fields are to be numeric and which are to be text when you set up the database in the first place. Numbers on which you might wish to perform arithmetic (item cost, quantity ordered, etc.) are typically stored in numeric fields; numbers on which you do not expect to perform arithmetic (customer number, telephone number, etc.) are typically stored in text objects.

ToNumber allows you to convert a Number stored as text to a Number on which you can perform arithmetic.

##### Typical uses

You might use this function, for example, if your item numbers contain coded product information and you want to use that information in calculations. Typically, you would be using this function to convert a Currency or String value that contains all numeric characters to a Number type value.

##### Examples

The following examples are applicable to both Basic and Crystal syntax:

`ToNumber({orders.ORDER AMOUNT})`

Returns a Number type value that the Currency field {orders.ORDER AMOUNT} contains.

`ToNumber("123.45")`

Returns 123.45.

`ToNumber({file.REFERENCE})`

Returns 200.00 where "200" is the text string in the {file.REFERENCE} field.

`ToNumber({file.ACCTNO}/2)`

Returns 22144 where {file.ACCTNO} = 44288.

`ToNumber({customers.POSTAL CODE}) < 33333`

Returns TRUE where {customer.POSTAL CODE} is "21385".

##### Comments

When using the ToNumber function, you should first test the value with the NumericText function. NumericText returns a value of TRUE only if the value in the string can be correctly converted to a Number. Otherwise, if you try to convert a value to a Number that is not a Number, the formula will produce an error in your report.

The following example is a common use of the NumericText and ToNumber functions together, in Crystal syntax:

If NumericText ({file.FIELD}) Then
ToNumber ({file.FIELD})
Else
0

###### Related topics

Formula 2

Formula 3

Formula 9

Formula 17

Seagate Software, Inc. http://www.seagatesoftware.com Please send comments to: techpubs@seagatesoftware.com