Re: Converting floats to ints with intval

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



On Thursday 06 May 2010 08:39:03 Bob McConnell wrote:
> From: David McGlone
>
> >On Thursday 06 May 2010 07:19:48 Paul Waring wrote:
> >> David Otton wrote:
> >> > On 6 May 2010 11:52, Paul Waring <paul@xxxxxxx> wrote:
> >> >> If I was designing the system from scratch, that's what I'd do.
> >> >> Unfortunately this is an add-on to a legacy system where currency
>
> values
>
> >> >> are already stored as strings in the database (yes, not ideal I
>
> know,
>
> >> >> but you have to work with what you've got).
> >> >
> >> > I don't know much about your situation, but it does sound like you
> >> > need to fix the root problem. I'd use a decimal type, and lean on
>
> the
>
> >> > database to do the maths.
> >>
> >> As I said, unfortunately it's a legacy system, so I can't just change
> >> the database to use a different type (there are dozens of columns set
>
> up
>
> >> like this, with thousands of values already set).
> >
> > Would It be possible to write a script to extract everything from that
> >
> > database and insert it into a database with the correct columns and
>
> values,
>
> > then all you would need to do is change the db connection information.
>
> If the data is really stored in strings, you need to break it down into
> substrings around the decimal and then convert both sides into integers
> and combine them into an integer value. It is the conversion into float
> that introduces the error because of the imprecise representation of
> fractional decimal values in binary.

I see.

-- 
Blessings,
David M.

-- 
PHP General Mailing List (http://www.php.net/)
To unsubscribe, visit: http://www.php.net/unsub.php


[Index of Archives]     [PHP Home]     [Apache Users]     [PHP on Windows]     [Kernel Newbies]     [PHP Install]     [PHP Classes]     [Pear]     [Postgresql]     [Postgresql PHP]     [PHP on Windows]     [PHP Database Programming]     [PHP SOAP]

  Powered by Linux