How to convert floating point type to string in php

藏色散人
Release: 2023-03-13 16:34:01
Original
2618 people have browsed it

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.

How to convert floating point type to string in php

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, '.', '');
Copy after login

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

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!

Related labels:
php
source:php.cn
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
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!