- Data Structure
- Networking
- RDBMS
- Operating System
- Java
- MS Excel
- iOS
- HTML
- CSS
- Android
- Python
- C Programming
- C++
- C#
- MongoDB
- MySQL
- Javascript
- PHP
- Physics
- Chemistry
- Biology
- Mathematics
- English
- Economics
- Psychology
- Social Studies
- Fashion Studies
- Legal Studies
- Selected Reading
- UPSC IAS Exams Notes
- Developer's Best Practices
- Questions and Answers
- Effective Resume Writing
- HR Interview Questions
- Computer Glossary
- Who is Who
PHP Floating Point Data Type
Definition and Usage
In PHP, float data type represents any number with a provision to contain a fractional part. The fractional part may contain digits after decimal point, or may be represented in scientific notation using either e or E. For example 100 in scientific notation is 10e2.
Size of a float depends on the hardware/OS platform, although precision upto 14 digits after decimal point is commonly found.
Syntax
//Literal assignment of float value to variable $var=5327.496; // standard notation $var1=5.327496e3; // Scientific notation $var2=5.327496E3; //Scientific notation $var3=5_327.496; //sepration symbol
For better readibility, integer literal may use "_" as separation symbol which will be omitted by PHP scanner while processing.
$var=5_327.496; // it will treated as 5327.496
PHP Version
Use of separation symbol "_" is avilable since PHP 7.40
Following example shows float literal representation in standard notations.
Example
<?php $var=5327.496; echo $var . "
"; ?>
Output
This will produce following result −
5327.496
This Example uses scientific notation
Example
<?php $var1=5.327496e3; <br /> echo $var . "
";<br />$var2=5.327496E3; <br /> echo $var . "
"; ?>
Output
This will produce following result −
5327.496 5327.496
This example using separation symbol "_" (This will run for PHP 7.40 onwards)
Example
<?php $var3=5_327.496; echo $var . "
"; ?>
Output
This will produce following result −
5327.496