php - How to convert a string number with text into numeric number
问题描述
I have a number like that : 342.50 EUR. How to table only the number : 342.50 I tried this, but it's not the result that I want
$str = '342.50 EUR';
preg_match_all('!\d+!', $str, $matches);
print_r($matches);
result : Array ( [0] => Array ( [0] => 342 [1] => 00 ) )
解决方案
如果你对失去最后一个没问题,0
那么你可以简单地使用floatval
:
$str = '342.50 EUR';
echo floatval($str); // 342.5
推荐阅读
- ffmpeg - 带 Alpha 通道的自适应视频编码
- r - 将多个excel文件作为一个数据框/表读取
- c# - Angular 9 http.delete 返回不支持的媒体 415
- c# - 使用 HoloLens 2 获取空间坐标系的正确方法
- android - 在 Room Kotlin 中插入改造响应
- asp.net-core - 如何在 ASP.Net Core 应用程序中向 Azure AD 身份验证用户添加自定义声明?
- android - 在 Android Studio 中运行单元测试时,类覆盖率和行覆盖率有什么区别?
- python - 如何从字典Python中获取值中的所有数组项
- datatables - jquery datatable ajax附加不需要的查询参数
- c++ - C ++中三角形的表面法线计算不正确