Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to specify decimal precision and scale number in MySQL using phpMyAdmin

SQL enables MySQL users to allocate a filed in Decimal format with specific Precision and Scale numbers as:

CREATE TABLE test_table
(
    test_column DECIMAL(6,4) NOT NULL
);

How can I do this in phpMyAdmin as the field type has only length/value option available there?

like image 924
Mona Coder Avatar asked May 26 '14 20:05

Mona Coder


People also ask

How do I get 2 decimal places in MySQL?

MySQL FORMAT() function MySQL FORMAT() converts a number to a format like '#,###,###. ##' which is rounded upto the number of decimal places specified (in the second argument) and returns the result as a string.

What is precision and scale in MySQL?

Precision is the number of digits in a number. Scale is the number of digits to the right of the decimal point in a number. For example, the number 123.45 has a precision of 5 and a scale of 2. In SQL Server, the default maximum precision of numeric and decimal data types is 38.


1 Answers

Decimals can be added to a MySQL database by using the DECIMAL(M,D) data type. This requires 2 arguments.

  • M is the maximum number of digits, ranging from 1 to 65.
  • D is the number of decimal places available, ranging from 0 to 30.

Note that with D digits reserved for decimal places, there can be at most M-D digits available for the integer part. So if we use DECIMAL(6,4), the number 45.8239 would be valid, but 456.12 would not.

To use this in phpMyAdmin, you can do the following:

In the Length/Value field type 6,4 without the parentheses.

enter image description here

results in a table structure like this:

enter image description here

like image 51
unutbu Avatar answered Sep 18 '22 09:09

unutbu