From: =?UTF-8?B?TWFydMOtbiBNYXJxdcOpcw==?= on
I have values with 2 decimals that I multiple by 100 to make them
integers, but to be sure I do a cast using (int).

The thing is that (int) is changing the value of the integer. Here is
a var_dump of the original value, the value * 100, and the value after
casting to int.

string(5) "34.80"
float(3480)
int(3479)

Using floor() those the exact same thing.

Why is this?

--
Martín Marqués
select 'martin.marques' || '@' || 'gmail.com'
DBA, Programador, Administrador
From: Paul M Foster on
On Thu, Aug 19, 2010 at 03:46:37PM -0300, Mart�n Marqu�s wrote:

> I have values with 2 decimals that I multiple by 100 to make them
> integers, but to be sure I do a cast using (int).
>
> The thing is that (int) is changing the value of the integer. Here is
> a var_dump of the original value, the value * 100, and the value after
> casting to int.
>
> string(5) "34.80"
> float(3480)
> int(3479)
>
> Using floor() those the exact same thing.
>
> Why is this?

Need to see your code. In cases like this, it's almost always been my
experience that the code is structured incorrectly to make it work the
way you expect.

Paul

--
Paul M. Foster
From: Nathan Rixham on
Martín Marqués wrote:
> I have values with 2 decimals that I multiple by 100 to make them
> integers, but to be sure I do a cast using (int).
>
> The thing is that (int) is changing the value of the integer. Here is
> a var_dump of the original value, the value * 100, and the value after
> casting to int.
>
> string(5) "34.80"
> float(3480)
> int(3479)
>
> Using floor() those the exact same thing.
>
> Why is this?
>

echo serialize("34.80" * 100);

3479.99999999999954525264911353588104248046875

int simply chops it, hence 3479

:)