Skip navigation links

MySQL Forums :: Newbie :: Decimal fields in tables


Advanced Search

Re: Decimal fields in tables
Posted by: Peter Brawley ()
Date: February 18, 2012 10:53AM

> I need db to store any value the user puts. any range!

Think again. There must be a limit to column width, and it is your job to define it.

> could be 10.000.000 (ten million) or 1.10

Again, you have to define a maximum value that can be stored. If it's ten million and three decimals, for example, that's decimal(11,3).

> They must be on the same table! makes no sense if I have to make diferent fields just by guessing how many zeros the user might enter!

Read again. Nobody mentioned different fields, nobody mentioned guessing.

drop table if exists t;
create table t(d decimal(11,3));
insert into t values(10000000.001),(1.001);
select * from t;
+--------------+
| d            |
+--------------+
| 10000000.001 |
|        1.001 |
+--------------+

If you want to control formatting more precisely, write a function in MySQL, or in your app language, to cover all formatting possibilities you wish to cover.

Options: ReplyQuote


Subject Written By Posted
Decimal fields in tables fio productions 02/16/2012 01:57PM
Re: Decimal fields in tables Peter Brawley 02/16/2012 02:36PM
Re: Decimal fields in tables fio productions 02/16/2012 02:16PM
Re: Decimal fields in tables Peter Brawley 02/16/2012 08:41PM
Re: Decimal fields in tables fio productions 02/17/2012 07:53AM
Re: Decimal fields in tables Peter Brawley 02/17/2012 11:18AM
Re: Decimal fields in tables fio productions 02/17/2012 09:09AM
Re: Decimal fields in tables Peter Brawley 02/17/2012 05:58PM
Re: Decimal fields in tables fio productions 02/18/2012 02:41AM
Re: Decimal fields in tables Peter Brawley 02/18/2012 10:04AM
Re: Decimal fields in tables fio productions 02/18/2012 11:00AM
Re: Decimal fields in tables Peter Brawley 02/18/2012 12:14PM
Re: Decimal fields in tables fio productions 02/18/2012 04:28PM
Re: Decimal fields in tables Peter Brawley 02/18/2012 10:53AM
Re: Decimal fields in tables fio productions 02/18/2012 06:16PM
Re: Decimal fields in tables Peter Brawley 02/18/2012 07:20PM


Sorry, you can't reply to this topic. It has been closed.

Content reproduced on this site is the property of the respective copyright holders. It is not reviewed in advance by Oracle and does not necessarily represent the opinion of Oracle or any other party.