# What is the rule of thumb in storing a percentage in a database, i.e., for 3 percent, ..03 or 3 [Answered]RSS

## 2 replies

Last post Oct 12, 2016 03:05 PM by Rion Williams

• JAYHAWKER

Participant

1238 Points

2687 Posts

### What is the rule of thumb in storing a percentage in a database, i.e., for 3 percent, ..03 or 3

I am curios as to what is a best practices method of storing percentages in a database. If it is 3%, I tend to store the 3. But I am just curios what others do considering you always have to divide by 100 to do math, and converting to percentage with .ToString("P2") multiplies it by 100.

• 0belix

Participant

1175 Points

777 Posts

### Re: What is the rule of thumb in storing a percentage in a database, i.e., for 3 percent, ..03 or...

I realy don't know if there is a best practice for this, but i usualy don't store percentages on the database, but rather the numbers that lead to them, and do the math via the store procedure or the codebehind that calls it. But if you really want to store the actual percentage, i'd opt for either store it as an integer (25% = 25) or if you need to use it to do some math inside the DB, store it as a decimal (25% = 0.25)

• Rion William...

All-Star

113110 Points

18361 Posts

MVP

### Re: What is the rule of thumb in storing a percentage in a database, i.e., for 3 percent, ..03 or...

Oct 12, 2016 03:05 PM|Rion Williams|LINK

I agree with Obelix here.

Percentages or at least values with percent signs generally fall under "formatting" in my option and as a result I generally avoid storing them that way (the same way you should store a timestamp instead of an actual formatted date string).

Depending on your level of precision, a decimal or float value might be best (i.e. 0.25, 0.125, 1.75, etc.) as that's a better mathematical representation of a percentage (generally a value between 0 (0%) and 1 (100%). If you would never need any fractional percentages, then I suppose an integer could be valid as well.