Converting a "string" to a number

Ask a Question related to Coldfusion Database Access, Design and Development.

  1. #1

    Default Converting a "string" to a number

    How do i convert a string (which is really a number, but just saved in the DB as 'text') into a number that can be added and subtracted?
    Explorer5 Guest

  2. Similar Questions and Discussions

    1. "Error Creating Control" and "Cast from String"
      I'm creating a custom date control. In appearance, it's just a textbox and a button. It has three custom properties: CalDate, CalDateType and...
    2. #26292 [Opn->Bgs]: substr returns "0" for any offset on the string "0"
      ID: 26292 Updated by: sniper@php.net Reported By: ravacholp at hotmail dot com -Status: Open +Status: ...
    3. #25763 [Opn->WFx]: Why the string "1.10" is equal to the string "1.1"?
      ID: 25763 Updated by: pollita@php.net Reported By: jparneodo at yahoo dot fr -Status: Open +Status: ...
    4. #25763 [NEW]: Why the string "1.10" is equal to the string "1.1"?
      From: jparneodo at yahoo dot fr Operating system: RH7.2 PHP version: 4.3.3 PHP Bug Type: Strings related Bug description: ...
    5. convert visual basic "string" data type to DB2 "blob"
      Does anyone know if a visual basic string data type can be converted to DB2 blob datatype? I have all data in XML files and I use Visual Basic to...
  3. #2

    Default Re: Converting a "string" to a number

    This would be for MS SQL, but there is probably similar syntax in MySQL and
    Access select cast(col1 as int) + col2 + cast(col3 as numeric(9,2) from table
    It gets a little stick for MS SQL 'text' datatypes (not varchar or char), you
    would need to cast the text data type to a varchar first, then cast to a int,
    numeric, etc. Also when adding int's and numeric, look out for rounding
    issues. int + numeric I believe will round to an int, you would need to cast
    both as numeric to get a floating number back

    byron1021 Guest

  4. #3

    Default Re: Converting a "string" to a number

    With Access, you can use CInt() or CLng() functions to convert a string to integer or LONG, whichever is applicable.

    SELECT CInt(col_name) AS num_col
    FROM whatever
    WHERE stuff

    Phil
    paross1 Guest

  5. #4

    Default Re: Converting a "string" to a number

    For Oracle use this: SELECT NVL( TO_NUMBER(col_txt), 0) * amt_nbr This
    converts any nulls to 0. If you are certain there are no nulls, just use the
    to_number(). There are other functions to convert to different datatypes, but
    this wil work for most applications.

    kyle969 Guest

Posting Permissions

  • You may not post new threads
  • You may post replies
  • You may not post attachments
  • You may not edit your posts

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139