Problem with MySQL Column Type

8 posts by 4 authors in: Forums > CMS Builder
Last Post: December 7, 2009   (RSS)

By Djulia - August 11, 2009 - edited: August 11, 2009

Hello,

I have a problem with the option MySQL Column Type.

I have a field of the Text type,
...and Custom Column Standard == DECIMAL

But, if I enter a value like 40.55, CmsB gives me 40.
It does not take into account the decimal.

Somebody has an idea
?
Thanks for your assistance, Djulia


http://help.scibit.com/Mascon/masconMySQL_Field_Types.html

Re: [Djulia] Problem with MySQL Column Type

By Chris - August 11, 2009

Hi Djulia,

MySQL is dropping your fraction. The MySQL DECIMAL column type should be defined with "precision" and "scale". For example: DECIMAL(10,2)

From the MySQL docs:


When declaring a DECIMAL or NUMERIC column, the precision and scale can be (and usually is) specified; for example:

salary DECIMAL(5,2)

In this example, 5 is the precision and 2 is the scale. The precision represents the number of significant digits that are stored for values, and the scale represents the number of digits that can be stored following the decimal point. If the scale is 0, DECIMAL and NUMERIC values contain no decimal point or fractional part.

Standard SQL requires that the salary column be able to store any value with five digits and two decimals. In this case, therefore, the range of values that can be stored in the salary column is from -999.99 to 999.99.

In standard SQL, the syntax DECIMAL(M) is equivalent to DECIMAL(M,0). Similarly, the syntax DECIMAL is equivalent to DECIMAL(M,0), where the implementation is allowed to decide the value of M. MySQL supports both of these variant forms of the DECIMAL and NUMERIC syntax. The default value of M is 10.

All the best,
Chris

Re: [chris] Problem with MySQL Column Type

By Djulia - August 11, 2009

Hi [font "Verdana"]Chris,

Thanks for your answer. :)

> [font "Verdana"]DECIMAL(10,2)
That corrected my problem !

Djulia

Re: [chris] Problem with MySQL Column Type

By Djulia - September 5, 2009

Hi Chris,

Which is best MySQL column type for IP address according to you ?

Thanks for your assistance.

Djulia

Re: [chris] Problem with MySQL Column Type

By Djulia - September 5, 2009 - edited: September 5, 2009

Hi Chris,

I think that I found an answer (BIGINT), ip2long(), long2ip().

It is an interesting article :
http://bafford.com/2009/03/09/mysql-performance-benefits-of-storing-integer-ip-addresses/

Djulia

Re: [Djulia] Problem with MySQL Column Type

By Dave - September 9, 2009

Djulia,

Glad you got it figured out, and thanks for posting the link! :)
Dave Edis - Senior Developer
interactivetools.com

Re: [WillTherman] Problem with MySQL Column Type

By Dave - December 7, 2009

Hi Will,

It would depend. What are you trying to do?
Dave Edis - Senior Developer
interactivetools.com