function transferToAddress(address _to, uint _value, bytes memory _data) internal returns (bool success) {
require (_to != msg.sender && _to != address(0));
uint fee = calculateFee(_value);
require (_value > 0);
require (balances[msg.sender] >= _value);
require (balances[_to].add(_value) >= balances[_to]);
uint sendAmount = _value.sub(fee);
balances[msg.sender] = balances[msg.sender].sub(_value);
balances[_to] = balances[_to].add(sendAmount);
if (fee > 0) {
balances[owner] = balances[owner].add(fee);
emit Transfer(msg.sender, owner, fee,_data);
}
holderIsExist(_to);
emit Transfer(msg.sender, _to, _value, _data);
emit Transfer(msg.sender, _to, _value);
return true;
}
function calculateFee(uint _amount)public view returns(uint){
uint fee = (_amount.mul(basisPointsRate)).div(1000);
if (fee > maximumFee) {
fee = maximumFee;
}
if (fee < minimumFee) {
fee = minimumFee;
}
return fee;
}发布于 2019-03-06 14:08:56
这不是为什么除以1000。这可能是没有被提升到权力的第10。背后的原因是
您不能在智能契约中使用小数。
因此,如果你想要有x%的费用呢?
你需要使用逻辑
fee = amount * x / 100;但是,x的最小值是1。因此,如果您希望x值低到0.1,您可以使用:
fee = amount * x / 1000;因此,当您需要的费用是10 %,在以后的情况下,您需要使用x= 100。
这类似于为什么我们在ERC-20令牌中有小数。
我个人的优势是有这样的划分是使用两个价值观的组合。
费用=金额* basisPointsRate_N / basisPointsRate_D
现在,您可以设置您想要的最小值。
https://ethereum.stackexchange.com/questions/67990
复制相似问题