DWQA QuestionsCategory: ProgramHow to convert the amount of Ethereum documents?
Ali_ asked 2 months ago

clipboard.png
Document address
https://ethereum.gitbooks.io/…

This document can't see how the amount here is converted,
I tried to convert from decimal to hexadecimal
Web3.towei method
I haven't seen the same effect. Please ask someone to answer it.

,0x9184e72a is indeed hexadecimal, but the unit is Wei, 1 eth = 10 ^ 18 Wei, and 1 eth is equal to the 18th power of 10. You can convert it into eth to verify it.
图片描述,The denomination unit of ether is three zeros in one file. Recommend an Ethereum DAPP development tutorial for novices:Introduction to Ethereum DAPP development

2 Answers
liuchengxu answered 2 months ago

0x9184e72a is indeed hexadecimal, but the unit is Wei, 1 eth = 10 ^ 18 Wei, and 1 eth is equal to the 18th power of 10. You can convert it into eth to verify it.
图片描述

Ali_ replied 2 months ago

It has been tested to convert to Wei unit first, and then to hexadecimal. However, the result of this method is that the result is too large for PHP to display. The result is 07fff right

liuchengxu replied 2 months ago

I’m not sure what you want to do. The comments on that line have told you that 0x9184e72a is converted into decimal system 24414062502441406250, and the 18th power of division by 10 is the value corresponding to eth.

Ali_ replied 2 months ago

Oh, thank you for your answer. I’ll test it again

Ali_ replied 2 months ago

Still there? My question is how to convert eth units to 0x9184e72a such a formatFor example, how can 0.01 eth be converted to this format (hexadecimal) -?1 eth = 10 ^ 18 Wei, then this parameter is not hexadecimal

liuchengxu replied 2 months ago

0.01 ETH = 10^16 wei, hex(10^16) = 0x2386f26fc10000

Ali_ replied 2 months ago

2386f26fc to hexadecimal is not equal to 10000

liuchengxu replied 2 months ago

The 2386f26fc10000 is completely connected. You can change it by yourself. In order to answer the questions, I have used Python conversion. Don’t be so lazy.

Ali_ replied 2 months ago

I converted it. The binary conversion result of PHP is wrong

liuchengxu replied 2 months ago

It has been tested with PHP and the results are the same.
<?php
$a = pow(10, 16);
echo base_convert($a, 10, 16);
?>

Ali_ replied 2 months ago

What is your PHP version? My 5.5.38 run, the code above is 3F8

liuchengxu replied 2 months ago

I don’t write PHPhttp://www.dooccn.com/php/

Ali_ replied 2 months ago

Try, my code can be found on your website. Not locally<?php
$a = pow(10,16);
echo dechex($a);
echo "<hr>";
$b = pow(10, 16);
echo base_convert($b, 10, 16);

?>

liuchengxu replied 2 months ago

You can go deep into the specific reasons. I won’t go deep into it. After all, I don’t write PHP.

Ali_ replied 2 months ago

thank. Read a posthttps://segmentfault.com/q/10…Prevent conversion to scientific counting first $num = number_ format($num, 0, ”, ”);Reuse base_ convert($num, 10, 16);To convert

vat2018 answered 2 months ago

The denomination unit of ether is three zeros in one file. Recommend an Ethereum DAPP development tutorial for novices:Introduction to Ethereum DAPP development