Recall & Review
beginner
What is a float in PHP?
A float is a number with a decimal point or in exponential form. It represents real numbers, like 3.14 or 2.5e3.
Click to reveal answer
intermediate
Why can floats have precision issues in PHP?
Floats are stored in binary, which can't exactly represent some decimal fractions. This causes small rounding errors.
Click to reveal answer
beginner
How can you control float precision when displaying numbers in PHP?
Use functions like number_format() or printf() to set how many decimal places to show.
Click to reveal answer
intermediate
What function can help compare floats safely in PHP?
Use a small tolerance value and check if the absolute difference is less than that, e.g., abs($a - $b) < 0.00001.
Click to reveal answer
intermediate
What is the typical size of a float in PHP?
A float usually uses 64 bits (double precision) following the IEEE 754 standard.
Click to reveal answer
What type of number does a float represent in PHP?
✗ Incorrect
Floats represent numbers with decimals or in exponential notation.
Why might 0.1 + 0.2 not exactly equal 0.3 in PHP?
✗ Incorrect
Floats are stored in binary, which can cause tiny rounding errors.
Which PHP function helps format a float to 2 decimal places?
✗ Incorrect
number_format() formats numbers with specified decimal places.
How should you compare two floats for equality in PHP?
✗ Incorrect
Due to precision errors, compare floats by checking if their difference is very small.
What is the typical precision of a PHP float?
✗ Incorrect
PHP floats usually use 64-bit double precision.
Explain why floats can cause precision problems in PHP and how to handle them.
Think about how computers store decimal numbers.
You got /3 concepts.
Describe how to safely compare two float numbers in PHP.
Consider tiny differences caused by float representation.
You got /3 concepts.