标准的常见实践方法,以实现任何类型的划分?
我试图以坚固的方式进行以下计算: 3,000 / 45,000,000 = 0.000067具有以下方法:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
function divide(uint _num1, uint _num2) public pure returns(uint _result) {
return (_num1 /_num2 );
}
但是显然,我将结果视为零。
我知道交易的坚固性使用了18个小数点(使用WEI),但是,我无法在重播所有有关固体中的小数如何处理常规数字或常规计算的问题。同样在大多数情况下,它甚至都不适合交易。
从“任何”数字中进行“任何”划分的实际常用标准实践方法是什么,无论是用于以太,代币或常规计算吗? 我的意思是一种适用于3 /100的方法以及2.5 / 3.7?
I am trying to do the following calculation with solidity:
3,000 / 45,000,000 = 0.000067 with the following method:
// SPDX-License-Identifier: MIT
pragma solidity ^0.8.0;
function divide(uint _num1, uint _num2) public pure returns(uint _result) {
return (_num1 /_num2 );
}
But obviously, I am getting the results as zero.
I am aware that solidity for transactions uses 18 decimal points (using Wei), however, I could not find in the replay to all the previous questions regarding the decimals in solidity how to do it for regular numbers, or regular calculations. Also most of the time it does not even work with transactions.
What is the actual commonly used standard practice method to do "ANY" division from "ANY" number, regardless being for Ether, Tokens, or regular calculations?
I mean a method that would work for 3 / 100 just as well as 2.5 / 3.7?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
坚固性不支持浮点算术,但是,如果您使用
uint256
,则可以使用定点算术算术值。Floating-point arithmetics are not supported in Solidity however you can use fixed-point arithmetics considering that you have 18 points of decimals if you use
uint256
.