php method to convert floating point type into string: 1. Create a PHP sample file; 2. Use the "number_format($float, 2, '.', '');" method to convert the floating point type into a string. Just convert the type number into a string.
The operating environment of this article: Windows7 system, PHP7.1 version, DELL G3 computer
How to convert floating point type into String?
Convert float to string in PHP
Method:
number_format($float, 2, '.', '');
The above result outputs a string with 2 decimal places. If you only want the integer part, change 2 to 0.
number_format() function formats a number by grouping by thousands.
Note: This function supports one, two or four parameters (not three).
Syntax
number_format(number,decimals,decimalpoint,separator)
Parameters
number Required. The number to format. If no other parameters are set, the number is formatted without a decimal point and with a comma (,) as the thousands separator.
decimals Optional. Specify the number of decimals. If this parameter is set, numbers are formatted using a period (.) as the decimal point.
decimalpoint Optional. Specifies the string used as the decimal point.
separator Optional. Specifies the string used as thousands separator. Only the first character of the parameter is used. For example, "xxx" only outputs "x".
Note: If this parameter is set, all other parameters are required.
Recommended learning: "PHP Video Tutorial"
The above is the detailed content of How to convert floating point type to string in php. For more information, please follow other related articles on the PHP Chinese website!