Get the App
SLTechnology News&Howtos  ›  Development  › 

How to convert integer type to floating point type by php

Shulou Source: shulou.com Published: 2022-06-01 06:00:08 09月30日 Update

Today, I would like to share with you the relevant knowledge of how php converts the whole type into a floating point. The content is detailed and the logic is clear. I believe most people still know too much about this knowledge, so share this article for your reference. I hope you can get something after reading this article. Let's take a look.

The way php converts an integer into a floating-point type: 1, use the floatval () function, the syntax is "floatval (integer value)"; 2, use the settype () function, and the syntax is "settype (integer value," float ").

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

Php converts an integer to a floating point type

Method 1: use the floatval () function

The floatval function is used to get the floating-point value of a variable.

Floatval cannot be used with arrays or objects.

Method 2:settype () function

The settype ($var,$type) function sets the variable $var to the specified data type $type.

Description:

The value of $type can be:

"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)

The settype () function changes the original variable.

These are all the contents of the article "how php converts integers to floating points". Thank you for reading! I believe you will gain a lot after reading this article. The editor will update different knowledge for you every day. If you want to learn more knowledge, please pay attention to the industry information channel.

Tags: Functions floating points knowledge articles variables methods content values grammars different large most objects that is tutorials data arrays more versions environment Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi Shulou Information Docker OPPO Reno Xiaomi