Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Initialize variable as float

Tags:

php

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;
like image 873
myol Avatar asked Jul 01 '26 17:07

myol


1 Answers

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.

like image 153
JesusTheHun Avatar answered Jul 06 '26 20:07

JesusTheHun



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!