Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support percent values #2

Open
totemcaf opened this issue Jul 16, 2022 · 1 comment
Open

Support percent values #2

totemcaf opened this issue Jul 16, 2022 · 1 comment
Labels
enhancement New feature or request

Comments

@totemcaf
Copy link

Money is usually used in context when a percent is computed on some money value, for example to compute an interest amount.

A Percent type could be added as a companion abstraction for money.

// Percent is a 3 decimal percent value. Internally it is stored as an int64 with a 3 digits scale
//   interestRate := percent.FromStr("3.5")
// It represents a 3.5% (a 0.03500) factor, and stored as 3500
type Percent int64

const Scale = 1000
const ScaledPercentToRate = 100 * Scale

func (p Percent) By(amount fpmoney.Amount) (computed fpmoney.Amount, remainder fpmoney.Amount) {
    return amount.Mul(int(p)).Div(ScaledPercentToRate)
}

Additional methods will be provided.

What do you think?

I can provide a PR.

@nikolaydubina
Copy link
Owner

Hi, yes, that is useful too. But I am not sure how much precision is necessary. I could imagine people want to have more than 1 fraction decimal for percentages.

Let's keep fpamount to deal only with {"amount" ... "currency"} pairs.

Do recommend for you to create new module / repo for percentages though if you are interested! :D

@nikolaydubina nikolaydubina added the enhancement New feature or request label Jul 16, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
enhancement New feature or request
Projects
None yet
Development

No branches or pull requests

2 participants