Tony Marston wrote:
"Pedro Graca" <he****@hotpop.com> wrote in message
news:sl*******************@ID-203069.user.uni-berlin.de... Steven wrote: I am wanting to store price data as n.nn format, so if the user enters
"1"
the data that gets stored is "1.00"
Is there a way to do this.
You have to define the column as text -- not a good idea!
Defining the column as text loses you the ability to make calculations
with values in that column; you can't sum a bunch of strings;
"28.00" < "4.00"; ...
Absolute rubbish! Every (competent ) database engine in the world is capable
of storing numeric fields, either as whole numbers (integers) or with
decimal places. It is a simple matter of choosing the right type. For MySQL
check out http://dev.mysql.com/doc/mysql/en/Numeric_types.html
That's what I think: having a text column with numeric values is
absolute rubbish :-)
Hope the OP does not go that way.
mysql> create table x (n int, v int, s varchar(10));
Query OK, 0 rows affected (0.00 sec)
mysql> insert x values(1, 28, "28.00"), (2, 4, "4.00");
Query OK, 2 rows affected (0.00 sec)
Records: 2 Duplicates: 0 Warnings: 0
mysql> select * from x order by v;
+------+------+-------+
| n | v | s |
+------+------+-------+
| 2 | 4 | 4.00 |
| 1 | 28 | 28.00 |
+------+------+-------+
2 rows in set (0.00 sec)
mysql> select * from x order by s;
+------+------+-------+
| n | v | s |
+------+------+-------+
| 1 | 28 | 28.00 |
| 2 | 4 | 4.00 |
+------+------+-------+
2 rows in set (0.00 sec)
mysql> drop table x;
Query OK, 0 rows affected (0.00 sec)
--
USENET would be a better place if everybody read: | to mail me: simply |
http://www.catb.org/~esr/faqs/smart-questions.html | "reply" to this post, |
http://www.netmeister.org/news/learn2quote2.html | *NO* MIME, plain text |
http://www.expita.com/nomime.html | and *NO* attachments. |