Skip to content

Price converter AggregatorV3Interface #788

Answered by 0xKMG
obc92 asked this question in Q&A
Discussion options

You must be logged in to vote
  1. In your given code there's no variable called ethValue, please update the code here so we can help!
  2. In any case you shouldn't try reducing the decimal point uint256(price/100000000) before, try follow the method introduced in the tutorial (giving them 18 decimal).
  3. Let's say all other things are fine in your code, since the calculation is uint256 EthAmount = DollaAmount/Price, whenever the input Dollar is less than the current eth price (e.g. $110, eth price $1100) , the return will be zero since 0.1 is not an int256.
  4. And for other cases the number will be extremely inaccurate: (e.g. $2100, eth price $1100, the return will be 1 but the correct amount is 1.90909.)
  5. conclusion: keep the floa…

Replies: 1 comment 1 reply

Comment options

You must be logged in to vote
1 reply
@obc92
Comment options

Answer selected by obc92
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants