0

从文档中, AggregatorV3Interface 返回..

Return Values
roundId: The round ID.
answer: The price.
startedAt: Timestamp of when the round started.
updatedAt: Timestamp of when the round was updated.
answeredInRound: The round ID of the round in which the answer
was computed.

也有人说这answer是一个int256。

我正在恢复价值120160203575

这是以美元为单位的8。

你如何将这个 unit8 格式化成美元格式的数字?(例如1201.00 美元).. 用小数格式化并去掉不需要的小数位?

4

1 回答 1

1

弄清楚了。Chainlink 可以decimals连同答案一起返回。

 function getLatestPrice() public view returns (int, uint8) {
    (
      uint80 roundID,
      int price,
      uint startedAt,
      uint timeStamp,
      uint80 answeredInRound
  ) = priceFeed.latestRoundData();

    uint8 decimals = priceFeed.decimals();
    return (price, decimals);
  }
于 2021-01-07T03:58:14.857 回答