Take the 2-minute tour ×
Database Administrators Stack Exchange is a question and answer site for database professionals who wish to improve their database skills and learn from others in the community. It's 100% free, no registration required.

I am using SQLite and need to store prices. SQLite's REAL data-type says it uses floating-point which is unacceptable storage for prices. Is there a data-type besides TEXT that I can use to store prices numerically so they sort correctly?

share|improve this question
add comment

2 Answers 2

up vote 12 down vote accepted

Use an integer & store the prices as the lowest common unit. So, for dollars and cents you'd store it in cents. EG: $1.00 would be stored as 100.

In my experience it's standard practice.

share|improve this answer
2  
It's extra work but this is the way to go - you also need a currency type field to store with the value so you know how to convert back. You need to pay attention, too - most currencies use 2 decimal places, but some use three. Check out ISO 4127 for the full list. –  lonstar Oct 1 '13 at 17:51
add comment

Certainly, use integer

You will have to decide how many decimal places you are assuming and be consistent at the application level.

share|improve this answer
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.