Settype()?

Im trying to convert my variable to a flout so I can use it in a mathematical operation but this doesn’t work

echo gettype($row['beginning_slot']);
echo gettype($row['ending_slot']);
$beginning_slot = settype($row['beginning_slot'], "float");		  
$ending_slot = settype($row['ending_slot'], "float");		  
echo gettype($beginning_slot);
echo gettype($ending_slot);

the result
stringstringbooleanboolean

don know wat that was about, but floatval() worked

https://www.php.net/manual/de/function.settype.php

First param of settype given by reference. You should check $row[‘beginning_slot’] and $row[‘ending_slot’], but you check returns of function settype(). Clear they are boolean.

1 Like

I wouldn’t use settype for this, but instead cast the value

$beginning_slot = (float) $row['beginning_slot'];
$ending_slot = (float) $row['ending_slot'];

Does beg the question though why times are stored as floats? :thinking:

timestamp with milliseconds?

Python records microseconds (10-6) of resolution in its timing functions. Sort of depends on the scope of the thing being timed.

the variables, beginning_slot & ending_slot are positions on a rack. (so the value is usually a whole number, and a few can be numbers like 4.2)

This topic was automatically closed 91 days after the last reply. New replies are no longer allowed.