PHP floating point data types

PHPz
Release: 2023-09-16 21:38:01
forward
1233 people have browsed it

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
Copy after login

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
Copy after login

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< /h2>

Live Demonstration

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

Output

This will produce the following results -

5327.496
Copy after login
Copy after login

This example uses scientific notation

Example

<?php
$var1=5.327496e3; <br />
echo $var . "";<br />$var2=5.327496E3; <br />
echo $var . "";
?>
Copy after login

Output

This will produce the following results -

5327.496
5327.496
Copy after login

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

Example

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

Output

This will produce the following results-

5327.496
Copy after login
Copy after login

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!

source:tutorialspoint.com
Statement of this Website
The content of this article is voluntarily contributed by netizens, and the copyright belongs to the original author. This site does not assume corresponding legal responsibility. If you find any content suspected of plagiarism or infringement, please contact admin@php.cn
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template
About us Disclaimer Sitemap
php.cn:Public welfare online PHP training,Help PHP learners grow quickly!