它输出173512312(1735.12312),但我只想要前4个字母
contract SimpleAuction {
AggregatorInterface internal ref;
// For ETH-USD on ropsten, input the address:
// 0x8468b2bDCE073A157E560AA4D9CcF6dB1DB98507
address _aggregator = 0x8468b2bDCE073A157E560AA4D9CcF6dB1DB98507;
string toni;
constructor() public {
ref = AggregatorInterface(_aggregator);
}
function getLatestAnswer() public view returns (int256) {
return ref.latestAnswer();
}
int256 private Limit;
//bool sell = false;
//this define input for limit
int256 yes = 1;
int256 no = 2;
function getEth(int256 price) public view returns (uint256){
}
//logic for limit
function setLimit(int256 newLimit) public {
Limit = newLimit;
sellLogic();
}
function sellLogic() private {
//if else to se if it will sell during the dump
int256 price = ref.latestAnswer();
if (price > Limit){
sell = true;
}else {
sell = false;
}发布于 2021-03-17 13:16:48
我不认为你想要前四个字母(字符)。现在很好,但是如果价格降到900美元会怎么样呢?你的系统会坏掉的。
你可能想要的是放弃最后5个数字。而且,最好是四舍五入(虽然只有当价格降到一些非常低的数字时,四舍五入才会开始起作用)。
因为这个值是一个整数,所以您可以只使用数字。要从173512312中删除最后5个数字,只需将其除以100000即可。因为Solidity不懂小数点,所以它只会去掉小数点,你就会得到1735。
https://ethereum.stackexchange.com/questions/94794
复制相似问题