Crystal Reports for Eclipse Designer Guide

ToNumber

ToNumber and CDbl are equivalent functions.
Description
ToNumber converts a Number, Currency, text string, or Boolean value to a Number.
Overloads
  • ToNumber (numeric)
  • ToNumber (string)
  • ToNumber (Boolean)
  • Arguments
  • numeric is a Number or a Currency type value.
  • string is a text string that holds numeric text.
  • Boolean is a Boolean value that you want to treat as a number.
  • Returns
    Fractional Number
    Action
    ToNumber converts a Number, Currency, text string, or Boolean value 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, and so on) are typically stored in numeric fields; numbers on which you do not expect to perform arithmetic (customer number, telephone number, and so on) 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.
    The Boolean argument enables you to treat SQL_BIT data values as if they were numbers.
    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
    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({customer.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
    



    SAP BusinessObjects
    http://www.sap.com/sapbusinessobjects/
    Support services
    http://service.sap.com/bosap-support/
    Product Documentation on the Web
    http://help.sap.com/