Jump to content

[SOLVED] Problem with DECIMAL and DOUBLE


terlynn4

Recommended Posts

Let me start by saying that I'm a newbie to MySQL so this could be user error; please feel free to state the obvious.

 

I am creating a table, and one of my variables is price, and I was using DECIMAL(4,2) as the type. When I entered my first item, I entered price as '159.99'. After I entered the item it said: Query OK, 1 row affected, 1 warning (0.00 sec). When I viewed the item I had just added, it displayed 99.99 as the value for price. I added a few more items to see what was happening, and it turned out that everything over 99.99 displayed 99.99 as the price, but everything less than that was correct. I double-checked that I had entered DECIMAL(4,2) instead of DECIMAL(2,2), but I had done it correctly. So I created a new table and used DOUBLE(4,2) as the type. It had the same results. All other types of variables work properly. Any idea what's going on or how to troubleshoot this?

 

Thanks in advance.

 

Edit: Sorry, I didn't read the forum posting rules until now. MySQL version is 5.0.26-12, and the following are my CREATE and INSERT codes:

CREATE TABLE jewelry (name VARCHAR(100), type VARCHAR(50), material VARCHAR(20), price DOUBLE(4,2), description TEXT, in_stock ENUM('yes','no'), ID int(11) NOT NULL auto_increment, PRIMARY KEY (ID));

INSERT INTO jewelry (name, type, material, price, description, in_stock) VALUES ('Diamond Heart Ring', 'Rings', '14K Yellow Gold', '199.99', 'Beautiful, contemporary, heart-shaped ring with five round diamonds.', 'yes');

Link to comment
Share on other sites

A friend just clarified things for me. The (4,2) means the total length of the number is 4 and there are two places after the decimal. I previously thought the first number was the length of the left side of the decimal. Thanks anyway!

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.