首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >坚实度为4位数

问坚实度为4位数
EN

Ethereum用户
提问于 2021-03-17 13:10:27
回答 1查看 193关注 0票数 0

它输出173512312(1735.12312),但我只想要前4个字母

代码语言:javascript
复制
    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;
        }
EN

回答 1

Ethereum用户

发布于 2021-03-17 13:16:48

我不认为你想要前四个字母(字符)。现在很好,但是如果价格降到900美元会怎么样呢?你的系统会坏掉的。

你可能想要的是放弃最后5个数字。而且,最好是四舍五入(虽然只有当价格降到一些非常低的数字时,四舍五入才会开始起作用)。

因为这个值是一个整数,所以您可以只使用数字。要从173512312中删除最后5个数字,只需将其除以100000即可。因为Solidity不懂小数点,所以它只会去掉小数点,你就会得到1735。

票数 1
EN
页面原文内容由Ethereum提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://ethereum.stackexchange.com/questions/94794

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档