Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/python/282.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
如何将WEI转换为etherphp_Php_Ethereum - Fatal编程技术网

如何将WEI转换为etherphp

如何将WEI转换为etherphp,php,ethereum,Php,Ethereum,我需要将类似0x2fe84e3113d7b的字符串转换为浮点类型。此字符串来自帐户的余额。我尝试过使用,但在这种情况下没有意义(它总是以任何方式返回0.00000)。如何使用php将此字符串转换为0.000842796652371 use Bezhanov\Ethereum\Converter; ... $this->converter = new Converter(); $weiValue = '0x1e1e83d93bb6ebb88bbaf'; dump($this->co

我需要将类似
0x2fe84e3113d7b
的字符串转换为浮点类型。此字符串来自帐户的余额。我尝试过使用,但在这种情况下没有意义(它总是以任何方式返回0.00000)。如何使用php将此字符串转换为
0.000842796652371

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
上的值太长造成的(我的意思是转换器不能像它那样转换长整数)。但是如何从这个十六进制数中得到乙醚值呢?

1乙醚=10000000000000000微(10^18)

由于这是货币,将其存储为浮点将是愚蠢的,因此它必须是一个64位整数

删除了我过度紧张的回答,原因很简单:

var_dump(
    $wei = hexdec("0x2fe84e3113d7b"),
    $wei / pow(10, 18)
);
输出:

int(842796652117371)
float(0.000842796652117370993)
巧合的是,这也说明了为什么您不想对货币使用浮动。另外,WFM

仍然无法解释为什么您有:

$hexValue = hexdec($weiValue); // returns 2.2757423599815E+24
在您的示例中引用为假设输入的错误数量级。

1乙醚=10000000000000000微(10^18)

由于这是货币,将其存储为浮点将是愚蠢的,因此它必须是一个64位整数

删除了我过度紧张的回答,原因很简单:

var_dump(
    $wei = hexdec("0x2fe84e3113d7b"),
    $wei / pow(10, 18)
);
输出:

int(842796652117371)
float(0.000842796652117370993)
巧合的是,这也说明了为什么您不想对货币使用浮动。另外,WFM

仍然无法解释为什么您有:

$hexValue = hexdec($weiValue); // returns 2.2757423599815E+24

在您的示例中引用,假设的输入错误了几个数量级。

您能显示您试图转换值的代码吗?@catcon更新了问题您能显示您试图转换值的代码吗?@catcon更新了问题