php 是否有一个解析字符串中指数的函数(例如:“9.5367431640625e-05”)或者是否必须通过正则表达式等手动完成?
php是否有一个函数可以转换字符串(数据类型将是字符串,因为它是从外部源解析的),例如:
string(..) "9.5367431640625e-05"
并对所述字符串执行指数计算并返回计算值?
或者我是否需要使用 regexp 等风格的方式来执行以下操作:
9.5367431640625e-05 -> 9.5367431640625^-5 = calculated value
如果 php 没有这样的功能,那么如何实现此功能的最佳想法?我只是想进行模式匹配之类的东西,有
/^([0-9\.\-]+)e([0-9\.\-]+)$/
更好的想法吗?
谢谢!
does php have a function that will convert a string (data type will be string since its parsed from an external source) like:
string(..) "9.5367431640625e-05"
and perform the exponent calculations on said string and return the calculated value?
or do i need to use regexp etc style way to do something like:
9.5367431640625e-05 -> 9.5367431640625^-5 = calculated value
if php does not have such a function, best ideas on how to accomplish this? i was just going to pattern match something like
/^([0-9\.\-]+)e([0-9\.\-]+)$/
any better ideas?
thanks!
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您可以进行简单的转换:
但是除了检查
0
(这可能是一个有效值......)之外,无法进行错误检查。您还可以使用 floatval() 函数来执行相同的操作。但通常您不必这样做,因为 PHP 会根据需要进行转换。请注意文档的该章:http://de.php。 net/manual/en/language.types.type-juggling.php
You could do a simple cast:
But besides checking for
0
(which might be a valid value ...) there is no way for error checking. You could also use thefloatval()
function which does the same.But usually you won't have to do it as PHP will cast as needed. Mind that chapter of the documentation: http://de.php.net/manual/en/language.types.type-juggling.php
进行演员表:
Do a cast: