Home  >  Article  >  Backend Development  >  PHP floating point data types

PHP floating point data types

PHPz
PHPzforward
2023-09-16 21:37:021234browse

PHP 浮点数据类型

Definition and Usage

In PHP, the float data type represents any number that contains a decimal part. The decimal part can contain digits after the decimal point, or it can be expressed in scientific notation using e or E. For example, 100 in scientific notation is 10e2.

The size of floating point numbers depends on the hardware/operating system platform, although it is common to find up to 14 digits of precision after the decimal point.

Syntax

Syntax H2>
//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 readability, integer literals can use "_" as delimiter, PHP scanner in This symbol will be ignored during processing.

$var=5_327.496; // it will treated as 5327.496

PHP Version

Since PHP 7.40 it is possible to use the delimiter symbol "_"

The following example shows the representation of floating point literals in standard notation.

Example

Live Demonstration

<?php
$var=5327.496;
echo $var . "";
?>

Output

This will produce the following results -

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 the following results -

5327.496
5327.496

This example uses the delimiter "_" (this will run starting from PHP 7.40)

Example

<?php
$var3=5_327.496;
echo $var . "";
?>

Output

This will produce the following results-

5327.496

The above is the detailed content of PHP floating point data types. For more information, please follow other related articles on the PHP Chinese website!

Statement:
This article is reproduced at:tutorialspoint.com. If there is any infringement, please contact admin@php.cn delete