Jump to content

[SOLVED] floatval always return 0


iplayfast

Recommended Posts

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?

 

Link to comment
Share on other sites

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

 

 

Link to comment
Share on other sites

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.

 

 

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.