Concept Flow - Float type and precision
Assign float value
Store in variable
Perform operations
Check precision
Display result
End
This flow shows how a float value is assigned, stored, operated on, and displayed with attention to precision.
<?php $a = 0.1 + 0.2; echo $a; ?>
| Step | Action | Expression | Result | Note |
|---|---|---|---|---|
| 1 | Assign 0.1 to variable | $a = 0.1 | 0.1 | 0.1 stored as float |
| 2 | Add 0.2 to $a | $a = 0.1 + 0.2 | 0.30000000000000004 | Float precision issue appears |
| 3 | Print $a | echo $a; | 0.30000000000000004 | Output shows precision error |
| Variable | Start | After Step 1 | After Step 2 | Final |
|---|---|---|---|---|
| $a | undefined | 0.1 | 0.30000000000000004 | 0.30000000000000004 |
Float type stores decimal numbers approximately. Adding floats can cause tiny precision errors. PHP prints floats showing these small errors. Use rounding or formatting to display clean numbers. Remember: floats are not exact for all decimals.