将以字符串形式显示的指数转换为小数 [英] Convert exponential number presented as string to a decimal

查看:256
本文介绍了将以字符串形式显示的指数转换为小数的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个字符串,其中包含"7.2769482308e + 01"(此数字来自第三方软件,我无法控制格式).

Let's suppose I have a string that contains "7.2769482308e+01" (this number came from 3rd party software, I cannot control the format).

将其转换为十进制72.769482308的最便宜方法是什么?

What is the cheapest way to convert it into decimal 72.769482308?

我能想到的唯一解决方案是拆分小数+指数部分并使用乘法.但是可能有一些内置的it函数可以执行相同的操作吗?

The only solution I can think of is to split decimal + exponential part and use multiplication. But may be there some built it function to do the same?

注意:伙计们,是的,我阅读了转换php中的指数到小数.那个问题无关紧要,因为它们已经有一个数字,但是我有一个字符串.

NOTE: Guys, yes, I've read Convert exponential to a whole number in PHP and Convert exponential number to decimal in php. And that questions are irrelevant, since they already have a number, but I have a string.

推荐答案

简单转换为浮点值怎么办?

What about a simple cast to a float value ?

$string = "7.2769482308e+01";
$float  = (float) $string;

这篇关于将以字符串形式显示的指数转换为小数的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆