Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

casting from double to int

Status
Not open for further replies.

keak

Programmer
Sep 12, 2005
247
CA
Hi there,
Say I have something like
$skip = $count / 16
where $count is some random number.

How would I cast the result into an int ?
I tried
$skip = int ($count / 16) but it is not giving me the expected result
 
Then I guess I'd be asking 'what IS your expected result ?'

int() truncates towards 0.... so (1.9) = 1, int(-1.9) = -1

try using 'sprintf'...
Code:
$nIntValue = sprintf("%d", $fDoubleValue);
 
Give some sample data and what you expect and what you are getting that you don't expect. Then maybe someone can post a suggestion or two.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top