In Postgresql, which field to use for percentage?

Asked

Viewed 1,246 times

4

In the table that I am creating, I will have a column that will indicate the discount percentage, for example, "for a given agreement I will have 20% discount, for another agreement I will have 50% discount", and I will need to use it in calculations for final cost, would you like to know what kind of field should I use to save that percentage? I thought I’d use decimal but I was in doubt.

1 answer

3


If you don’t have decimals you can use the integer or smallint, otherwise the decimal is a good choice. Only won’t use real or something like that. I think you already know this guy has problems with financial calculations.

  • 1

    Is the real type equal to the double type? What kind of problems occur?

  • 1

    @Andrewalex Almost, the real has "less precision" but has the same kind of problem. For scientific calculations it works well but for monetary calculations it does not. See more on the subject at http://answall.com/a/38140/101. See the numerical types of Postgresql: http://www.postgresql.org/docs/9.4/static/datatype-numeric.html

Browser other questions tagged

You are not signed in. Login or sign up in order to post.