cryptography - 格式化 Chainlink AggregatorV3Interface 对美元的“答案”?
问题描述
从文档中, 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 美元).. 用小数格式化并去掉不需要的小数位?
解决方案
弄清楚了。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);
}
推荐阅读
- java - 河内塔之类的
- android - 如何为所有系统语言启用活动
- android - 是否可以使用 ARCore 在存储的图像上“应用”AR?
- google-sheets - 将单元格公式字符串的一部分格式化为超链接
- sumologic - 如何使用 NQL 在相扑逻辑中设置警报
- javascript - 高亮行没有按预期工作 jquery
- c++ - 如何在 C++ 中允许自定义返回类型的成员函数进行类型擦除?
- sharepoint - SharePoint 加载项与 Dynamics 应用程序结合使用?
- redis - Laravel Redis 工作失败:队列 --tries=3 --stop-when-empty
- angularjs - textarea 没有显示正确的值