Warning: file_get_contents(/data/phpspider/zhask/data//catemap/1/php/226.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php 如何将数字格式的输出转换为数字?_Php - Fatal编程技术网

Php 如何将数字格式的输出转换为数字?

Php 如何将数字格式的输出转换为数字?,php,Php,我想将数字格式的输出(如129888.0)转换为1298880,以便在从db编辑时返回函数 谢谢如果$string是数字格式的输出,那么这将通过删除任何非数字字符使其返回数字 $number = preg_replace('/[^\d]/', null, $string); 另一方面,您应该真正存储未格式化的内容,并在需要显示它们时对其进行格式化。您到底想做什么?只需将129888.0转换为1298880?如果您只想删除逗号,则不需要preg_replace,您可以使用str_replace(

我想将数字格式的输出(如129888.0)转换为1298880,以便在从db编辑时返回函数


谢谢

如果
$string
是数字格式的输出,那么这将通过删除任何非数字字符使其返回数字

$number = preg_replace('/[^\d]/', null, $string);

另一方面,您应该真正存储未格式化的内容,并在需要显示它们时对其进行格式化。

您到底想做什么?只需将129888.0转换为1298880?如果您只想删除逗号,则不需要
preg_replace
,您可以使用
str_replace(',',null,$string)
 $numstr = "100,000,000.75";
 $num = doubleval(str_replace(",",".",$mynumstr));