Handling Decimal format

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • thatos
    New Member
    • Aug 2007
    • 105

    Handling Decimal format

    I have the following create statement
    Code:
    $query = "CREATE TABLE P(
     code int(2) NOT NULL,
     value decimal(3.6) NOT NULL,
     PRIMARY KEY(code)
    
    ";
    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
  • johny10151981
    Top Contributor
    • Jan 2010
    • 1059

    #2
    the correct syntax is value decimal(3,6) not 3.6

    Comment

    • thatos
      New Member
      • Aug 2007
      • 105

      #3
      When I do that, the table is not created, look at the code below.
      Code:
      $Isotope = "CREATE TABLE Isotope (
      	isotope_id int(2) NOT NULL auto_increment,
      	isotope_name varchar(50) NOT NULL,
      	state int(1) NOT NULL,
      	unit varchar(10) NOT NULL,
      	min_value decimal(3,6) NOT NULL,
      	max_value decimal(3,6) NOT NULL,
      	PRIMARY KEY (isotope_id)
      )";
      $results = mysql_query($Isotope);

      Comment

      • johny10151981
        Top Contributor
        • Jan 2010
        • 1059

        #4
        Please read the syntax in the documentation
        Syntax for Decimal

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

        Comment

        Working...