Complete the code to declare a float variable with value 3.14.
<?php
$pi = [1];
echo $pi;
?>The correct way to assign a float value is using a number with a decimal point like 3.14.
Complete the code to print the float value with 2 decimal places.
<?php $number = 3.14159; echo number_format([1], 2); ?>
Use the variable $number inside number_format to format the float.
Fix the error in the code to correctly compare two float values.
<?php $a = 0.1 + 0.2; $b = 0.3; if (abs($a - $b) < [1]) { echo "Equal"; } else { echo "Not equal"; } ?>
Because of floating point precision, we check if the difference is less than a small number like 0.0001 to consider them equal.
Fill both blanks to create an array of floats and sum them.
<?php $values = array([1], [2]); $sum = array_sum($values); echo $sum; ?>
The array contains floats 1.5 and 2.5. Their sum is 4.0.
Fill all three blanks to create a float, round it, and print the result.
<?php $value = [1]; $rounded = round([2], [3]); echo $rounded; ?>
Assign 3.6789 to $value, then round $value to 2 decimal places.
