Network Security Internet Technology Development Database Servers Mobile Phone Android Software Apple Software Computer Software News IT Information

In addition to Weibo, there is also WeChat

Please pay attention

WeChat public account

Shulou

How to convert php strings to floating-point data

2025-02-25 Update From: SLTechnology News&Howtos shulou NAV: SLTechnology News&Howtos > Development >

Share

Shulou(Shulou.com)06/02 Report--

This article focuses on "how to convert php strings into floating-point data". Interested friends may wish to take a look. The method introduced in this paper is simple, fast and practical. Let's let the editor learn how to convert php strings into floating-point data.

Conversion method: 1, add the target type "(float)", "(double)" or "(real)" enclosed in parentheses before the string variable; 2, use the "floatval (string)" statement; 3, use the "settype (string variable," float ")" statement.

Operating environment of this tutorial: windows7 system, PHP7.1 version, DELL G3 computer

Convert php strings to floating-point data

Method 1: precede the string variable with the target type "(float)", "(double)" or "(real)" enclosed in parentheses

(float), (double), (real): convert target variables to floating-point types

Example:

Output result:

Method 2: use the floatval () function

Floatval (): used to get the floating-point value of a variable

Output result:

Method 3: use the settype () function

The settype () function sets the type of variable.

Syntax: settype (mixed & $var, string $type)

$type: the possible value of type is.

"boolean" (or "bool", starting with PHP 4.2.0)

"integer" (or "int", starting with PHP 4.2.0)

"float" (available only after PHP 4.2.0, "double" used in older versions is now disabled)

"string"

"array"

"object"

"null" (since PHP 4.2.0)

Example:

Output:

Note: the settype () function changes the original type of the variable, returning TRUE if the setting is successful and FALSE if it fails.

At this point, I believe you have a deeper understanding of "how to convert php strings into floating-point data". You might as well do it in practice. Here is the website, more related content can enter the relevant channels to inquire, follow us, continue to learn!

Welcome to subscribe "Shulou Technology Information " to get latest news, interesting things and hot topics in the IT industry, and controls the hottest and latest Internet news, technology news and IT industry trends.

Views: 0

*The comments in the above article only represent the author's personal views and do not represent the views and positions of this website. If you have more insights, please feel free to contribute and share.

Share To

Development

Wechat

© 2024 shulou.com SLNews company. All rights reserved.

12
Report