Solved

MySQL is rounding out and trunking the number

Posted on 2009-06-28
7
418 Views
Last Modified: 2013-11-05
Hi Every one,

I have  mySQL server running on a VM, its been working fine, and I have over 200,000 record saved on it, until couple of days ago that one of the user entered $ amount of 33448.67 on the application, but on the MySQL it got saved 33448.70  ( instead of .67 got saved as .70) I tried to edit it in the MySQL but it did a same thing,  is jut trunking it up. I removed one digit from the beginning decimal digits and it got saved fine!!

I looked at the field parameters, the Data type of this field is "Float"  I tried to change it to double but it wouldn't change and I got an error that Field " is not valid!

I tried to change the Width and decimals and still I got a error message too.

I have to say that I'm using Webmin interface to connect to the Mysql

any suggestion?
0
Comment
Question by:kiarash13581979
  • 3
  • 2
7 Comments
 
LVL 1

Author Comment

by:kiarash13581979
Comment Utility
This is the error message that I get when tried to change it from "Float" to "Double":
Failed to save field : '' is not a valid field size
0
 
LVL 3

Expert Comment

by:tcsaddul9
Comment Utility
MySQL performs rounding when storing values, so if you insert 999.00009 into a FLOAT(7,4) column, the approximate result is 999.0001

You should use the field type Numeric (P, S) or Decimal (P, S)

(P, S) means P is the precision and S is the scale sometimes stated as P is the width and S is the decimal places to the right of period.  For example: Numeric (10, 2) would have a 10 digit precision and 2 as scale or simply call it 10 is the width and 2 decimal places.
0
 
LVL 1

Author Comment

by:kiarash13581979
Comment Utility
if I change my current fata field from "Float" to Numeric(10, 2) what will happen to my current data that are in the Database? I just don't want any changes to the current data. and I just want to make sure that I don't loose or change any of them.
0
 
LVL 1

Author Comment

by:kiarash13581979
Comment Utility
I have tried to change but I get the error message bellow from Webin tool that use:

Failed to save field : SQL alter table `items` modify `amount` float(10,2) null default none  failed : You have an error in your SQL syntax; check the manual that corresponds to your MySQL server version for the right syntax to use near 'none' at line 1
0
 
LVL 3

Accepted Solution

by:
tcsaddul9 earned 500 total points
Comment Utility
There is an error in the 'DEFAULT' clause of your statement. Please try this:

alter table `items` modify `amount` numeric(10,2) null default '0.00'

In my apps, I make sure that null is not used, so I use something like this:

alter table `items` modify `amount` numeric(10,2) NOT null default '0.00'



0

Featured Post

Highfive + Dolby Voice = No More Audio Complaints!

Poor audio quality is one of the top reasons people don’t use video conferencing. Get the crispest, clearest audio powered by Dolby Voice in every meeting. Highfive and Dolby Voice deliver the best video conferencing and audio experience for every meeting and every room.

Join & Write a Comment

Suggested Solutions

Foreword This is an old article.  Instead of using the MySQL extension that was used in the original code examples, please choose one of the currently supported database extensions instead.  More information is available here: MySQLi / PDO (http://…
Load balancing is the method of dividing the total amount of work performed by one computer between two or more computers. Its aim is to get more work done in the same amount of time, ensuring that all the users get served faster.
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…

762 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now