标准的常见实践方法,以实现任何类型的划分?

发布于 2025-01-28 11:36:35 字数 447 浏览 1 评论 0原文

我试图以坚固的方式进行以下计算: 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

北音执念 2025-02-04 11:36:35

坚固性不支持浮点算术,但是,如果您使用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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文