By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
432,510 Members | 1,810 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 432,510 IT Pros & Developers. It's quick & easy.

Handling Decimal format

thatos
100+
P: 105
I have the following create statement
Expand|Select|Wrap|Line Numbers
  1. $query = "CREATE TABLE P(
  2.  code int(2) NOT NULL,
  3.  value decimal(3.6) NOT NULL,
  4.  PRIMARY KEY(code)
  5.  
  6. ";
  7.  
but when I look at the data field using phpadmin, value is (3.0) , and when I insert a value say "123.123456" this number gets converted to 123.

I just want to know how to represent a decimal in an sql statement for mysql
Oct 22 '11 #1

✓ answered by johny10151981

Please read the syntax in the documentation
Syntax for Decimal

Name DECIMAL(M,D) // M>=D

Share this Question
Share on Google+
3 Replies


100+
P: 1,059
the correct syntax is value decimal(3,6) not 3.6
Oct 24 '11 #2

thatos
100+
P: 105
When I do that, the table is not created, look at the code below.
Expand|Select|Wrap|Line Numbers
  1. $Isotope = "CREATE TABLE Isotope (
  2.     isotope_id int(2) NOT NULL auto_increment,
  3.     isotope_name varchar(50) NOT NULL,
  4.     state int(1) NOT NULL,
  5.     unit varchar(10) NOT NULL,
  6.     min_value decimal(3,6) NOT NULL,
  7.     max_value decimal(3,6) NOT NULL,
  8.     PRIMARY KEY (isotope_id)
  9. )";
  10. $results = mysql_query($Isotope);
  11.  
Oct 24 '11 #3

100+
P: 1,059
Please read the syntax in the documentation
Syntax for Decimal

Name DECIMAL(M,D) // M>=D
Oct 24 '11 #4

Post your reply

Sign in to post your reply or Sign up for a free account.