Fenguoz / tron-php

Support TRON's TRX and TRC20, which include functions such as address creation, balance query, transaction transfer, query the latest blockchain, query information based on the blockchain, and query information based on the transaction hash
MIT License
194 stars 65 forks source link

TRC20转账中 hexdec($body->constant_result[0]) 出现科学计数的问题 #4

Closed ghost closed 3 years ago

ghost commented 3 years ago

环境: MacOS Big Sur + Nginx + PHP-FPM,使用 php think run 启动调试。

PHP 7.3.27 (cli) (built: Feb 27 2021 18:04:51) ( NTS ) Copyright (c) 1997-2018 The PHP Group Zend Engine v3.3.27, Copyright (c) 1998-2018 Zend Technologies with Zend OPcache v7.3.27, Copyright (c) 1999-2018, by Zend Technologies

hexdec($body->constant_result[0]) 报错,打印结果大概是:1.123456E+6,然后 Utils::toDisplayAmount 方法里报错了,临时解决方案如下:

$balance = Utils::toDisplayAmount(hexdec($body->constant_result[0]), $this->decimals); to: $balance = Utils::toDisplayAmount(number_format(hexdec($body->constant_result[0]), 0, '', ''), $this->decimals);

Fenguoz commented 3 years ago

解决科学计数法数字格式问题tag1.3.0