Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

VARCHAR field sort like a number 1

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I have a "price" field in my database and I want it to sort in the same way a number field would. Only problem is i'm storing my values in a VARCHAR field because they are in this format: 2342.00

So by default it sorts it like it's text and doesn't put things in the right order. Any way around this?

_______________
_brian.
 
Ok, I figured out the proper way to do this by using the FLOAT field type, rather than the VARCHAR. Then i just use PHP number_format to put my commas in. Thanks!

_______________
_brian.
 
caution: FLOAT is only an approximate datatype

for prices, use DECIMAL instead

also, you can use the mysql FORMAT function to automatically insert the commas

r937.com | rudy.ca
 
Thanks for the help rudy. I'm using PHP to add my commas but if I need to switch, that tip is very helpful.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top