Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > PHP/MySQL > PHP Databases
Password Reminder
Register
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read
PHP Databases Using PHP in conjunction with databases. PHP questions not specific to databases should be directed to one of the other PHP forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the PHP Databases section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Reply
 
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old December 7th, 2003, 12:31 AM
Authorized User
 
Join Date: Oct 2003
Location: KL, wilayah persekutuan, Malaysia.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default decimal values is rounded

i have create the mysql table as below. My problem is with the prod_price.
i enter the price as decimal but the value i get when i retrieve it is the rounded value of what i have entered.
1. Could someone tell me why?
2. How am i going to make the sql to stored the values?
    (as entered because i need it to do calculation using the exact value)

CREATE TABLE PRODUCT
(
    PROD_ID VARCHAR(5) NOT NULL,
    PROD_NAME VARCHAR(20) NOT NULL,
    PROD_DESC VARCHAR(20) NOT NULL,
    PROD_PRICE DECIMAL(6,2) NOT NULL,
    PROD_BRAND INT NOT NULL,
    PRIMARY KEY(PROD_ID),
    FOREIGN KEY(PROD_BRAND) REFERENCES BRAND,
);

INSERT INTO PRODUCT VALUES('H001', 'THOMPSON', 'ACTIVATED GINGKO EXTRACT', 92.80, 1);
INSERT INTO PRODUCT VALUES('H002', 'SUPRADYN', 'MULTIVITAMIN PREPARATION', 68.90, 1);
INSERT INTO PRODUCT VALUES('H003', 'BIOGROW', 'GINGKO PHYTOSOME', 49.60, 1);

mysql> select prod_id, prod_price from product
+---------+------------+
| prod_id | prod_price |
+---------+------------+
| H001 | 93.00 |
| H002 | 69.00 |
| H003 | 50.00 |



Reply With Quote
  #2 (permalink)  
Old December 7th, 2003, 02:40 AM
richard.york's Avatar
Wrox Author
Points: 5,506, Level: 31
Points: 5,506, Level: 31 Points: 5,506, Level: 31 Points: 5,506, Level: 31
Activity: 0%
Activity: 0% Activity: 0% Activity: 0%
 
Join Date: Jun 2003
Location: Camby, IN, USA.
Posts: 1,706
Thanks: 0
Thanked 6 Times in 6 Posts
Default

I'm looking through the MySQL manual and I'm not immediately seeing what could be wrong there.

What I can deduce from the manual which says the following:

Quote:
quote:From: http://www.mysql.com/doc/en/Numeric_types.html

DECIMAL and NUMERIC values are stored as strings, rather than as binary floating-point numbers, in order to preserve the decimal precision of those values...
..since they are stored as strings perhaps you must enclose the value in quotes in order to get the database to preserve precision values.

I haven't tested it out myself. Give that a go and see if it makes a difference.

: )
Rich

:::::::::::::::::::::::::::::::::
Smiling Souls
http://www.smilingsouls.net
:::::::::::::::::::::::::::::::::
Reply With Quote
  #3 (permalink)  
Old December 9th, 2003, 01:50 AM
Authorized User
 
Join Date: Oct 2003
Location: KL, wilayah persekutuan, Malaysia.
Posts: 91
Thanks: 0
Thanked 0 Times in 0 Posts
Default

thanks! i finally found out what happen.After i drop the product table and then create and insert value into the table, everything is fine. Maybe because at first i create the prod_price decimal then i modify it to become decimal(8,2) so there's a error. When i then recreate the table with prod_price decimal(8,2), it works fine.

Reply With Quote
Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
sorting decimal values in xsl SOMANATHAN10 XSLT 1 May 10th, 2007 07:47 AM
decimal data type all 0's after decimal gobotsoup SQL Server ASP 1 February 28th, 2007 02:32 PM
Allowing Decimal values bright_mulenga Access 1 February 12th, 2007 12:38 PM
Returning Decimal values from database hasanali00 BOOK: ASP.NET Website Programming Problem-Design-Solution 3 October 10th, 2005 08:10 PM
How to add two variable with Decimal values sa_moizatyahoo ASP.NET 1.0 and 1.1 Basics 1 April 3rd, 2004 06:17 AM



All times are GMT -4. The time now is 09:06 PM.


Powered by vBulletin®
Copyright ©2000 - 2019, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.