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 Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

MySQL Decimal Field Predicament

Status
Not open for further replies.

bdichiara

Programmer
Oct 11, 2006
206
US
I have a decimal field set to 50,2 in my table. The problem is this field can hold numbers without decimals, for example:

20.20
30.59
5
14
35.70

In my PHP code, i check to see if it has a decimal, and that's how I know that it's money, so I add number_format() to the value. My problem is when I'm sorting the field, it puts 5 before 14. I'm guessing because the 5 is greater than the 1.

Whats the solution to this situation?

_______________
_brian.
 
No, I'm ordering it by the decimal field in the MySQL query.

here's my query:
Code:
SELECT * FROM poe LEFT JOIN employees ON poe.employee = employees.employeeid LEFT JOIN poe_cats ON poe.category = poe_cats.categoryid ORDER BY poe.category ASC, poe.amount DESC

here is a section of my results:
Code:
Most Checking Accounts Opened
1   Some Employee Name           4
2   Some Other Employee Name     25
3   Another Name                 23
4   Name Again                   15
4   Stuff                        15
5   Boom                         14

_______________
_brian.
 
4 is at the top of the list, where it should be at the bottom.

_______________
_brian.
 
if you remove the category ordering does it then work?
 
CRAP! You know what... I just checked and my table field is a varchar.....

I'm sorry to have wasted your time with that. I guess now my question is, can I change this field to a Decimal field (50,2) and still have values that do not use .00 at the end?

_______________
_brian.
 
Actually, now that i figured out my problem, i should probably post over in the MySQL forum. Thanks sleipnir for the help.

_______________
_brian.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top