【发布时间】:2019-12-09 23:26:13
【问题描述】:
我需要将0x2fe84e3113d7b 之类的字符串转换为浮点类型。此字符串来自 infura.io API 作为帐户余额。我尝试使用https://github.com/mbezhanov/ethereum-converter,但在这种情况下没有任何意义(它总是以任何方式返回 0.00000)。如何用php将此字符串转换为0.000842796652117371?
use Bezhanov\Ethereum\Converter;
...
$this->converter = new Converter();
$weiValue = '0x1e1e83d93bb6ebb88bbaf';
dump($this->converter->fromWei($weiValue)); // returns 0.00000000000000000000000000000000000
$hexValue = hexdec($weiValue); // returns 2.2757423599815E+24
dump($this->converter->fromWei($hexValue)); // returns the same
我猜这是$hexValue 上的值过长造成的(我的意思是转换器不能像它一样转换长整数)。但是如何从这个十六进制中获取以太值呢?
【问题讨论】:
-
你能在你尝试转换值的地方显示你的代码吗?
-
@catcon 更新了问题