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

Decimal Types

Status
Not open for further replies.

ShaunaH

Programmer
Joined
Jun 4, 2002
Messages
3
Location
US
I'm still new to mySQL. I'm trying to display rates in a decimal format that goes out at least two spaces but at maximum three places from the decimal... But I don't want the third place to show unless it's defined. (For example it would show 11.11 and 11.111 -- right now it's showing 11.110 and 11.111...

How can I accomplish this?

I've been using "decimal(6,3)" as my data type.
 
I don't know wheter its possible with MySql itself, but try this:

a) get the value out of mysql
b) do a round on the second umber after the decimal in your favorite programming/scripting language
c) compare the mysql value with the just rounded: if its equal, truncate the rounded and display it, if not, display the mysql value.

got the idea?

it's a bit like a shot in the back through the eye in your feet, but it should work... cu, Sascha
 
this should strip all the zeros from the end of your data

select substring_index(decimal_column,'0',1) from yourtable

or this only the last one (i hope - have not tested ;-))

select if(right(decimal_column,1)='0',left(decimal_column,length(decimal_column)-1),decimal_column) from yourtable

 
Status
Not open for further replies.

Similar threads

Part and Inventory Search

Sponsor

Back
Top