iplayfast Posted January 20, 2008 Share Posted January 20, 2008 I thought I understood this function but it's always giving me 0 as a result. $t = trim($out[0][$k+3]); echo '$t is '. $t. ' floatval($t) is '. floatval($t); echo '<br>type of t is '. gettype($t); returns $t is -0.25 floatval($t) is 0 type of t is string always return 0 no matter what the value of $t is. I assume that the result is false, but I don't know why. Anybody help? Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/ Share on other sites More sharing options...
toplay Posted January 20, 2008 Share Posted January 20, 2008 What version of php are you running? When I run this code with PHP v4.3.11: <?php $t = trim('-0.25'); echo '$t is '. $t. ' floatval($t) is '. floatval($t); echo '<br>type of t is '. gettype($t); ?> I get this output fine: $t is -0.25 floatval($t) is -0.25 type of t is string Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444178 Share on other sites More sharing options...
Barand Posted January 20, 2008 Share Posted January 20, 2008 If the output is not as expected and the code is OK, check the input. Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444190 Share on other sites More sharing options...
iplayfast Posted January 20, 2008 Author Share Posted January 20, 2008 If the output is not as expected and the code is OK, check the input. Wise words. HTML tags were messing me up. Thanks Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444407 Share on other sites More sharing options...
toplay Posted January 20, 2008 Share Posted January 20, 2008 $t is -0.25 floatval($t) is 0 type of t is string I know what Barand says makes sense of course, but iplayfast, please explain about the HTML tags messing you up, because your original post shows "$t is -0.25" as the input data? Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444451 Share on other sites More sharing options...
Barand Posted January 20, 2008 Share Posted January 20, 2008 In the original post it was $t = trim($out[0][$k+3]); Perhaps a result of some parsing? But just guessing. Better let him tell us. Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444454 Share on other sites More sharing options...
toplay Posted January 20, 2008 Share Posted January 20, 2008 Perhaps a result of some parsing? But just guessing. Better let him tell us. I would normally agree with you, but he immediately follows the $t assignment with displaying it's value on the echo line. I can only conclude, that his original post is not really accurate to what was really happening for him. Quote Link to comment https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/#findComment-444459 Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.