View Full Version : Dynamic Text Field/MYSQL

07-17-2008, 07:32 PM
I have a dynamic text field that gets a price entered into. When the form is submitted, the database (MYSQL) shows it as a rounded number.

For Example:

entered price is 5.95
in the mysql database the data says 5

07-17-2008, 09:23 PM
Please post only one thread. Making two will not get anymore attention.
Here's the answer:

07-18-2008, 04:25 AM
Is the datatype of the field in your database integer by any chance? It would automatically drop the decimal part upon loading.

For currency fields, I usually use float (8,2) but someone here probably knows what is best.

07-18-2008, 01:54 PM
i probably should have stated this. The form is in dreamweaver and gets submitted to my database. From the point that it gets inputted into to dreamweaver when you go view the record in the database it has been rounded.

How do I prevent that from being rounded.

07-18-2008, 02:12 PM
Where is your dreamweaver and where is your database? My DreamWeaver is on my PC and is an editor, not a browser. Is your database on the web or your PC? If you do not do any calculations with the data, you could make it a text field and then it would retain your format. I still think it is the datatype of the field.

07-18-2008, 02:15 PM
my dreamweaver is an editor too. my mysql database is on the web.

right now it is a regular text field and when i type 5.95 and submit the data and then go look at the record in my mysql database it says 5

07-18-2008, 02:21 PM
It is truncating, not rounding. Check to see how wide your field is. Is it a varchar or char datatype, or what is the exact definition? You should not be using TEXT datatype as that is huge. What does it say in the Type colum??

07-18-2008, 02:22 PM
in dreamweaver where the price is entered is a text field and the char is set to 7.
in mysql database the price is set to decimal(3,2)

07-18-2008, 02:30 PM
When you say Dreamweaver, I assume you mean html. PLease put the html here for the form containing the text field, and change the field def to float 6,2 in the table. I once imported a table using ODBC from MySQL with prices in decimal(8,2) fields and all the decimal values were dropped (sound familiar?). This didn't happen after I changed the def to float.

07-18-2008, 02:33 PM
this is what the price field looks like in dreamweaver is .php

<td class="KT_th"><label for="price_<?php echo $cnt1; ?>">Price:</label></td>
<td><input type="text" name="price_<?php echo $cnt1; ?>" id="price_<?php echo $cnt1; ?>" value="<?php echo KT_escapeAttribute($row_rsmenu_items['price']); ?>" size="7" />
<?php echo $tNGs->displayFieldHint("price");?> <?php echo $tNGs->displayFieldError("menu_items", "price", $cnt1); ?></td>

07-18-2008, 06:12 PM
how do i stop it from truncating?

07-18-2008, 06:33 PM
Dear Smitty: I've been up all night and need to get some sleep now. Have you defined a datatype for the price variable? I'm just learning php so this is a bit beyond me. There are some great people on DD who know infinitely more than I. But I'd look at this and see exactly what it is doing. Good luck! Sorry I can't be of more help.


07-22-2008, 08:51 PM
Still need some help if anyone knows anything?

08-02-2008, 06:24 AM
I believe your query asks us a very important question.
what type is best for price?
Our first instinct might go for a number, but price is in the form XX.XX, so we can not just use any number form, we need it to support decimal places, for `float', `double', `real' and `decimal' we can specify the size and number of decimal places that we want to be able to use so I would suggest one of these is used and due to the limitations of `float' and `double/real' I would suggest using `decimal/numeric' to show our prices, although this field type does actually store the values as a string I believe it is the best for our needs.

I hope this answers your question... Let me know... I experienced this on a recent project i am doing and it very well fulfill my need.