Converting to decimal

Ask a Question related to ASP Database, Design and Development.

  1. #1

    Default Converting to decimal

    I've imported some data from a mainframe db via text
    file. The file contains this:

    credit_hours pic 9(2)v9 (COBOL, it basically says 3 number
    fields with an implied decimal before the last number)

    For simplicity, I imported it as char(3)

    Now it shows up in SQL as:
    050

    Using the cast command, I would like it to show up as:
    05.0 (my cast statement -> select cast(credit_hours as dec
    (3,1)) from table) now it show as this -> 50.0

    How can I get it in the desired output using the cast
    command or any other suggestions?

    Thanks

    Shawn Guest

  2. Similar Questions and Discussions

    1. decimal vs. int vs. numeric ???
      First, I apologize if this is posted in the wrong area ... it has to do with mySQL and ASP ... I had two fields in a mySQL table: cost quantity...
    2. decimal to hex and back
      how can i change decimal to hex and back?? thanxxx andrea
    3. Converting from decimal to hex
      Hi. I have an array consisting of mac addresses in decimal form seperated by : Like this: 0:0:33:195:37:6 0:0:180:75:15:17 and so on I now...
    4. converting HH:MM to a decimal
      I have 3 pairs of time in/out (24 our clock) that I need to calculate the decimal equivalent of the total time worked for that day. example: ...
    5. do not cut decimal places
      Hi, following problem (oracle8): I want to insert a value with precision (#.##) in a number(10,2) column. It works but the values which end with...
  3. #2

    Default Re: Converting to decimal

    > For simplicity, I imported it as char(3)
    >
    > Now it shows up in SQL as:
    > 050
    >
    > Using the cast command, I would like it to show up as:
    > 05.0 (my cast statement -> select cast(credit_hours as dec
    > (3,1)) from table) now it show as this -> 50.0
    >
    > How can I get it in the desired output using the cast
    > command or any other suggestions?
    Are there always three digits, and always a trailing number that is supposed
    to represent the first decimal place? If so, then:

    SELECT CONVERT
    (
    DECIMAL(3, 1),
    LEFT(credit_hours, 2) + '.' + RIGHT(credit_hours, 1)
    )
    FROM table

    You could also use SUBSTRING(), or STUFF().

    However, instead of worrying about presentation, you should focus on getting
    the data stored in the right way.


    Aaron Bertrand - MVP Guest

  4. #3

    Default Re: Converting to decimal

    Correct you are, if I have it stored correctly then I
    would not need to worry about this. I wanted to test the
    DTS import first to ensure the data was acceptable, now I
    will change my DTS import to import the decimal fields the
    correct way. When I tried to import is using dec(3,1) it
    did not work correctly, but I think I will need to run a
    line of T-SQL script to alter the data after it is in the
    Db as part of the DTS. DOes that sound correct? Yes, the
    field is always 3 digits trailing number that is supposed
    to represent the first decimal place.

    Thanks
    >-----Original Message-----
    >> For simplicity, I imported it as char(3)
    >>
    >> Now it shows up in SQL as:
    >> 050
    >>
    >> Using the cast command, I would like it to show up as:
    >> 05.0 (my cast statement -> select cast(credit_hours as
    dec
    >> (3,1)) from table) now it show as this -> 50.0
    >>
    >> How can I get it in the desired output using the cast
    >> command or any other suggestions?
    >
    >Are there always three digits, and always a trailing
    number that is supposed
    >to represent the first decimal place? If so, then:
    >
    >SELECT CONVERT
    >(
    > DECIMAL(3, 1),
    > LEFT(credit_hours, 2) + '.' + RIGHT(credit_hours, 1)
    >)
    >FROM table
    >
    >You could also use SUBSTRING(), or STUFF().
    >
    >However, instead of worrying about presentation, you
    should focus on getting
    >the data stored in the right way.
    >
    >
    >.
    >
    Shawn Guest

  5. #4

    Default Re: Converting to decimal

    Hi, Shawn
    dim dec 'as double
    dim pic 'as string
    dec = (val(pic)) / 10 <-- Implied decimal(V) with 1/10.

    "Shawn" <programming@jards.com> wrote in message news:<005101c367f0$4c433230$a101280a@phx.gbl>...
    > I've imported some data from a mainframe db via text
    > file. The file contains this:
    >
    > credit_hours pic 9(2)v9 (COBOL, it basically says 3 number
    > fields with an implied decimal before the last number)
    >
    > For simplicity, I imported it as char(3)
    >
    > Now it shows up in SQL as:
    > 050
    >
    > Using the cast command, I would like it to show up as:
    > 05.0 (my cast statement -> select cast(credit_hours as dec
    > (3,1)) from table) now it show as this -> 50.0
    >
    > How can I get it in the desired output using the cast
    > command or any other suggestions?
    >
    > Thanks
    Peter Chong 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