Home  >  Article  >  Backend Development  >  How to remove thousandth place of amount in php

How to remove thousandth place of amount in php

WBOY
WBOYOriginal
2022-02-14 10:33:153966browse

In PHP, you can use the "str_replace" function to remove the thousandth digit of the amount. This function is used to replace some characters in the string. Just set the parameters in the function to replace the comma in the thousandth digit. The syntax is "str_replace(",","",amount string)".

How to remove thousandth place of amount in php

The operating environment of this tutorial: windows10 system, PHP7.1 version, DELL G3 computer

How to remove the thousandths of the amount in php

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.

Note: This function is case-sensitive. Please use the str_ireplace() function to perform a case-insensitive search.

Note: This function is binary safe.

Syntax

str_replace(find,replace,string,count)

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.

Return value: Returns a string or array with replacement value.

The example is as follows:

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

Output result:

How to remove thousandth place of amount in php

Recommended learning: "PHP Video Tutorial"

The above is the detailed content of How to remove thousandth place of amount in php. For more information, please follow other related articles on the PHP Chinese website!

Statement:
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