Learn Mysql:mysql with Mr. Wang decimal type of data type

Source: Internet
Author: User

Learn Mysql:mysql with Mr. Wang decimal type of data type
Teacher: Wang Shaohua QQ Group No.: 483773664
Learning content

What are decimal types and their range of values

Define the meaning of M and d in the syntax

The difference between fixed-point and floating-point types


First, Introduction

In MySQL, you use a floating-point type and a fixed-point number type to represent decimals.

Floating-point types include single-precision floating-point numbers (float type) and double-precision floating-point numbers (double).

The fixed-point number type is decimal.

Second, byte number, value range

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A5/wKiom1d5vN6CJyhWAABYCfYvEfI502.png "alt = "Wkiom1d5vn6cjyhwaabycfyvefi502.png"/>

Iii. Definition of grammar

1

类据类型 (M,D)

M: Accuracy, total length of data

D: Scale, length after the decimal point

Note:

The decimal point does not occupy the length eg:float (6,2) 1234.56

M affects storage range, Eg:float (6,2) -9999.99~~~9999.99

If the insertion value is more accurate than the actual defined precision, the system automatically rounds the processing. (Here the rounding takes the form of a bank, i.e. if the 5 front number is 1279, i.e. 5 is not in, if 5 front is 2468, then 5 into)

Iv. example (i) float
1 Build a commodity table goods

1

2

3

4

createtablegoods(

   namevarchar(10),

   price float(6,2)

);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A4/wKioL1d5vN6TxYUJAAAZy6HKJMg541.png "alt = "Wkiol1d5vn6txyujaaazy6hkjmg541.png"/>

2 inserting values

1

insertintogoods(name,price) values(‘跑步机‘,688.6);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M00/83/A5/wKiom1d5vN6CEriLAAAYgBCrg0Q704.png "alt = "Wkiom1d5vn6cerilaaaygbcrg0q704.png"/>

(ii) fixed-point and floating-point differences 1 decimal relative more precise

1. Add two columns

1

2

altertable goods addbigprice float(9,2);

altertable goods adddeciprice decimal(9,2);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A4/wKioL1d5vN7xAmcQAAAzow0khQk676.png "alt = "Wkiol1d5vn7xamcqaaazow0khqk676.png"/>

2 Inserting data

1

insertintogoods(name,bigprice,deciprice)values(‘自行车‘,1234567.23,1234567.23);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A5/wKiom1d5vN6S5OxxAAAigB866Js890.png "alt = "Wkiom1d5vn6s5oxxaaaigb866js890.png"/>

Cause: Decimal is stored as characters in the database, and if you want to compare the accuracy of the data, or select the fixed-point number

2 default accuracy is not the same

If you do not specify precision, the float and fixed point numbers have their default precision.

float and double types save actual precision by default

Decimal type default integer bit is 10, decimal place is 0

To add a field:

1

2

3

altertable goods adda float;

altertable goods addb double;

altertable goods addd decimal;

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M01/83/A5/wKiom1d5vN7Bz8RHAAAa7pVzO_4481.png "alt = "Wkiom1d5vn7bz8rhaaaa7pvzo_4481.png"/>

Insert data:

1

insertintogoods (name,a,b,d) values(‘汽车‘,3.143,3.143,3.143);

650) this.width=650; "border=" 0 "src=" http://s3.51cto.com/wyfs02/M02/83/A4/wKioL1d5vN_gGVSdAAAnO5MGn1g088.png "alt = "Wkiol1d5vn_ggvsdaaano5mgn1g088.png"/>

V. Teaching VIDEO

Http://edu.51cto.com/course/course_id-6420.html




This article is from "Learn programming with Mr. Wang" blog, please be sure to keep this source http://teacherwang.blog.51cto.com/10946447/1795475

Learn Mysql:mysql with Mr. Wang decimal type of data type

Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.