将变量初始化为float

Never had to do such a basic thing before. How do I initialize a variable as a float before doing logic? Do either of these examples make sense?

$var = 0.0;

$var = (float) 0;

Both make sense, the first is shorter, with the second you can initialized with a dynamic value, your choice !

EDIT : But I agree with @Niet the Dark Absol, it poorly matters since you use test function such as ctype_digit, or is_numeric.

Try to use number_format.

For example:

$number = 20;
echo number_format($number,2) // will output 20.00
// number_format($number,$decimals,$dec_point,$thousands_sep)

from http://php.net/manual/en/language.types.float.php

Floating point numbers (also known as "floats", "doubles", or "real numbers") can be specified using any of the following syntaxes:

<?php
$a = 1.234; 
$b = 1.2e3; 
$c = 7E-10;
?>

so defining a float by using $var = 0.0 is correct. While casting is not technically incorrect I don't believe it's something you should use when you don't need to.