Skip to content

Recommended way to get a percentage? #73

Closed Answered by PaulRBerg
0x6080 asked this question in Q&A
Discussion options

You must be logged in to vote

Hey @kenvogg, there are examples in the README.

In your case, you would write:

function takePercentage(uint256 x) external pure returns (uint256 result) {
  const percentage = .25e18; // 0.25 means 25%
  result = x.mul(percentage);
}

To be honest I don't see the value of a perc function. It'd be just syntactic sugar for mul.

Replies: 1 comment 6 replies

Comment options

You must be logged in to vote
6 replies
@PaulRBerg
Comment options

@0x6080
Comment options

@PaulRBerg
Comment options

@0x6080
Comment options

@PaulRBerg
Comment options

Answer selected by 0x6080
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Category
Q&A
Labels
None yet
2 participants
Converted from issue

This discussion was converted from issue #73 on February 15, 2022 18:34.