Why can't I cast this float to int?

PHP programming forum. Ask questions or help people concerning PHP code. Don't understand a function? Need help implementing a class? Don't understand a class? Here is where to ask. Remember to do your homework!

Moderator: General Moderators

Post Reply
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Why can't I cast this float to int?

Post by tores »

Hi.

I divide to numerics and get 33.670033670034
Then I do a ceil() and get 34
But when I try to convert/cast (float) 34 to (int) 34 I get no result...

Is there some hidden overflow or something I'm missing?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

this sure seems to work

Code: Select all

<?php

$foo = 33.670033670034;

var_dump($foo);
echo "\n";
var_dump(ceil($foo));
echo "\n";
var_dump((int)ceil($foo));

?>
outputs

Code: Select all

float(33.670033670034)

float(34)

int(34)
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

It sure does... After some testing I got it working to... Guess it must have been some variable mismatch or something else that went by undetected :?
User avatar
feyd
Neighborhood Spidermoddy
Posts: 31559
Joined: Mon Mar 29, 2004 3:24 pm
Location: Bothell, Washington, USA

Post by feyd »

the fun of having E_NOTICE turned off, maybe..
tores
Forum Contributor
Posts: 120
Joined: Fri Jun 18, 2004 3:04 am

Post by tores »

Probably :wink:
Post Reply