Home > Backend Development > PHP Problem > How to cancel thousandth place after number formatting in php

How to cancel thousandth place after number formatting in php

WBOY
Release: 2023-03-16 12:18:01
Original
1651 people have browsed it

In PHP, you can use the "str_replace()" function to format the number and cancel the thousandth place. This function is used to replace some characters in the string. You only need to use this function to replace the characters in the number. The thousandths symbol is sufficient, and the syntax is "str_replace(",","",number)".

How to cancel thousandth place after number formatting in php

The operating environment of this article: Windows 10 system, PHP version 8.1, Dell G3 computer

Cancel thousandths

str_replace() function replaces some characters in a string (case sensitive).

This function must follow the following rules:

If the searched string is an array, then it will return an array.

If the searched string is an array, then it will find and replace each element in the array.

If an array needs to be searched and replaced at the same time, and the elements to be replaced are less than the number of found elements, the excess elements will be replaced with empty strings.

If you search an array and replace only one string, the replacement string will work on all found values.

Syntax

str_replace(find,replace,string,count)
Copy after login

Parameter Description

find Required. Specifies the value to look for.

replace Required. Specifies the value to replace the value in find.

string Required. Specifies the string to be searched for.

count Optional. A variable counting the number of substitutions.

The example is as follows:

<?php
$a=number_format("1000000",2);
echo $a."<br>";
echo str_replace(",","",$a);
?>
Copy after login

Output result:

How to cancel thousandth place after number formatting in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to cancel thousandth place after number formatting 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
Popular Tutorials
More>
Latest Downloads
More>
Web Effects
Website Source Code
Website Materials
Front End Template