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
https://forums.phpfreaks.com/topic/86881-solved-floatval-always-return-0/
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

 

 

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.

 

 

Archived

This topic is now archived and is closed to further replies.

×
×
  • 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.