Professional Web Applications Themes

How to convert a column of integers to float(4.2)?? - MySQL

This is a newbie, and I suspect, a question with a very easy number. I'm surprised googling wasn't much help. How do I convert a whole column of of integers to numbers with 4 digits before and 2 digits after a decimal point? For example, 2091 becomes 20.91 and 124 becomes 1.24 in the table? Thanks!...

  1. #1

    Default How to convert a column of integers to float(4.2)??

    This is a newbie, and I suspect, a question with a very easy number.
    I'm surprised googling wasn't much help.

    How do I convert a whole column of of integers to numbers with 4
    digits before and 2 digits after a decimal point?

    For example, 2091 becomes 20.91 and 124 becomes 1.24 in the table?

    Thanks!
    Pete Guest

  2. #2

    Default Re: How to convert a column of integers to float(4.2)??

    Pete wrote: 

    The answer depends on how the column is defined. Is it an integer column?


    Paul Guest

  3. #3

    Default Re: How to convert a column of integers to float(4.2)??

     

    It's an integer column. I'd like to convert the entire column from
    integer to float, and in the process also convert the integer values
    therein to float(4.2) format.

    Pete Guest

  4. #4

    Default Re: How to convert a column of integers to float(4.2)??

    Pete wrote: 
    >
    > It's an integer column. I'd like to convert the entire column from
    > integer to float, and in the process also convert the integer values
    > therein to float(4.2) format.
    >[/ref]

    I'm not sure you really want to do this.

    If it is a monetary value, chances are it's better this way. The reason
    is simple - an integer is an exact value. However, a floating point
    number is almost always an approximation, and subject to rounding errors.

    In most cases when I'm writing a shopping cart, I keep the prices as
    integers and only convert to floating point when I'm ready to display it.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  5. #5

    Default Re: How to convert a column of integers to float(4.2)??



    I've been googling for the past couple of hours and other people seem
    to say the same thing. Is that how it's done in other database
    platforms too? Is that how you and other always do it? When does one
    use float then? Thank you.

    Pete Guest

  6. #6

    Default Re: How to convert a column of integers to float(4.2)??

    On 12 Mar, 05:33, Pete <com> wrote: 

    >
    > I've been googling for the past couple of hours and other people seem
    > to say the same thing. Is that how it's done in other database
    > platforms too? Is that how you and other always do it? When does one
    > use float then? Thank you.[/ref]

    The other alternative is tio use the DECIMAL data type.

    Captain Guest

  7. #7

    Default Re: How to convert a column of integers to float(4.2)??

    Pete wrote: 
    >
    > I've been googling for the past couple of hours and other people seem
    > to say the same thing. Is that how it's done in other database
    > platforms too? Is that how you and other always do it? When does one
    > use float then? Thank you.
    >[/ref]

    It's not just database platforms. It's almost any floating point number
    on a PC (mainframes have a PACKED DECIMAL type which takes care of this).

    Floating point numbers on a PC are stored as powers of 2, not as
    decimals. That means 1/10 cannot be represented exactly - it is a
    repeating decimal, much like 1/3 is in decimal notation.

    The only fractional values which can be represented exactly are 1/2,
    1/4, 3/8, etc.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  8. #8

    Default Re: How to convert a column of integers to float(4.2)??

    Captain Paralytic wrote: 
    >> I've been googling for the past couple of hours and other people seem
    >> to say the same thing. Is that how it's done in other database
    >> platforms too? Is that how you and other always do it? When does one
    >> use float then? Thank you.[/ref]
    >
    > The other alternative is tio use the DECIMAL data type.
    >[/ref]

    This works only if the underlying language also supports a DECIMAL type.
    Many, i.e. C/C++, would convert this to float anyway.

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  9. #9

    Default Re: How to convert a column of integers to float(4.2)??

    On Mon, 12 Mar 2007 09:30:53 -0500, Jerry Stuckle wrote: 

    As an amusing aside, I had a relative that worked maintaining a
    financial ysis package for stock portfolios on a mainframe back in
    the day. As soon as the NYSE announced that they were going to start
    trading in dollars and cents instead of dollars and fractional dollars,
    he announced his retirement plans. The transaction prices were all
    stored as 16-bit values, with the least three bits as the fraction part
    of the dollar. I think his total contribution to the conversion effort
    was to say "Scale everything by 800."

    --
    Don't use this code for realtime control, for weapons systems, or for
    anything else that may put life or limb at hazard. It isn't man-rated,
    it isn't really thing-rated, and we don't claim that it's worth a good
    G*dDamn for anything at all, at all. -- Mike Andrews, on Java compilers
    Peter Guest

  10. #10

    Default Re: How to convert a column of integers to float(4.2)??

    Peter H. Coffin wrote: 
    >
    > As an amusing aside, I had a relative that worked maintaining a
    > financial ysis package for stock portfolios on a mainframe back in
    > the day. As soon as the NYSE announced that they were going to start
    > trading in dollars and cents instead of dollars and fractional dollars,
    > he announced his retirement plans. The transaction prices were all
    > stored as 16-bit values, with the least three bits as the fraction part
    > of the dollar. I think his total contribution to the conversion effort
    > was to say "Scale everything by 800."
    >[/ref]

    I can believe that, Peter.

    People wonder why the NYSE didn't go to dollars and cents much earlier.
    Now those who read this group do :-).

    --
    ==================
    Remove the "x" from my email address
    Jerry Stuckle
    JDS Computer Training Corp.
    net
    ==================
    Jerry Guest

  11. #11

    Default Re: How to convert a column of integers to float(4.2)??

    On Mon, 12 Mar 2007 13:02:58 -0500, Jerry Stuckle
    <net> wrote:
     [/ref][/ref]

    Ok, so integers it is.

    Now how do I convert a column of float values to integers? Thanks.
    Pete Guest

Similar Threads

  1. Convert float value to integer
    By afroman22 in forum Coldfusion - Getting Started
    Replies: 2
    Last Post: October 27th, 07:12 PM
  2. Convert units to integers in determining width?
    By eagle in forum ASP.NET Data Grid Control
    Replies: 1
    Last Post: August 8th, 06:43 PM
  3. How to convert string to float?
    By Jason Chan in forum ASP
    Replies: 4
    Last Post: September 4th, 12:51 PM
  4. Convert / Decimal / Float
    By Marco in forum Microsoft SQL / MS SQL Server
    Replies: 2
    Last Post: August 6th, 07:47 PM
  5. Convert an MS Access Yes/No column to a checkbox column in C# datagrid
    By Gregory Rampton in forum ASP.NET Data Grid Control
    Replies: 0
    Last Post: August 6th, 04:09 PM

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not 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