Float, Decimal or Integer trong Drupal Fields?

Float, Decimal or Integer trong Drupal Fields?

Drupal comes with 13 fields and several of them deal with numbers.

Newcomers to Drupal can become confused about the difference because there are 5 different number fields available:Float, Decimal or Integer trong Drupal Fields?

  1. Decimal

  2. Float

  3. Integer

  4. List (float)

  5. List (integer)

In this tutorial, we're going to explain the difference between those 5 number fields and explain when you would use each one.

Integer

Integer is the easiest table of number field to understand. Integer is another word for whole numbers.

Integers are whole numbers such as 1, 2, 3, 10 or 500. This is ideal for numbers such as ages or years.

There are no settings at all for Integer fields:

media_1387475209862.png

You can't enter any spaces, letters or any punctuation into Integer fields.

Things such as spaces, commas or decimal points are added from the Manage Display tab:

media_1387475385532.png

Decimal

The Decimal field allows numbers with fractions.

You can decide on three settings for the field, including:

  • Precision: the total number of digits, both before and after the decimal point.

  • Scale: the number of digits after the decimal point.

So in the example below, a Scale of 2 would be ideal for storing prices. This is because there can only be two numbers to the right of the decimal point in prices such as $32.89

media_1387475296029.png

As with all of the number fields, you can't enter any spaces, letters or any punctuation into Integer fields.

Things such as spaces, commas or decimal points are added from the Manage Display tab:

media_1387475358659.png

Float

Float is definitely the most confusing of the umber fields.

Here's our simple rule: if you don't know what a floating point number is, you don't need to use the Float field.

However, for those of you that don't know but are curious, here's a quick explanation:

"Floating point" is a term used in computer programming. Basically, floating point numbers are numbers that contain floating decimal points.

Here's the best, simple explanation I've read about why floating points are used: http://floating-point-gui.de/formats/fp/

"Since computer memory is limited, you cannot store numbers with infinite precision, no matter whether you use binary fractions or decimal ones: at some point you have to cut off. But how much accuracy is needed? And where is it needed? How many integer digits and how many fraction digits?

  • To an engineer building a highway, it does not matter whether it’s 10 meters or 10.0001 meters wide - his measurements are probably not that accurate in the first place.
  • To someone designing a microchip, 0.0001 meters (a tenth of a millimeter) is a huge difference - But he’ll never have to deal with a distance larger than 0.1 meters.
  • A physicist needs to use the speed of light (about 300000000) and Newton’s gravitational constant (about 0.0000000000667) together in the same calculation.

To satisfy the engineer and the chip designer, a number format has to provide accuracy for numbers at very different magnitudes. However, only relative accuracy is needed. To satisfy the physicist, it must be possible to do calculations that involve numbers with different magnitudes.

Basically, having a fixed number of integer and fractional digits is not useful - and the solution is a format with a floating point."

Here are the field settings for a Float in Drupal. The only thing you can choose is whether to use a decimal point or a comma.

media_1387475251888.png

The Manage Display settings are the same as for Decimal.

media_1387475326005.png

List (float) and List (integer)

Both of these fields allow you to create a list of pre-defined choices. Unlike the other 3 fields, people will not be allowed to enter their own numbers.

media_1387477816235.png

If you choose "Check boxes/radio buttons", then this is how the options will show. If you want to remove the N/A option, set the field to be required.

media_1387477879075.png

If you choose "Select list", then this is how the options will show:

media_1387477972391.png

Bạn thấy bài viết này như thế nào?: 
No votes yet
Ảnh của Khanh Hoang

Khanh Hoang - Kenn

Kenn is a user experience designer and front end developer who enjoys creating beautiful and usable web and mobile experiences.

Tìm kiếm bất động sản

 

Advertisement

 

jobsora

Dich vu khu trung tphcm

Dich vu diet chuot tphcm

Dich vu diet con trung

Quảng Cáo Bài Viết

 
7 bước xây dựng  Responsive Theme trong Drupal 7

7 bước xây dựng Responsive Theme trong Drupal 7

Based on the grid system and the nature of your design, download grids from http://960.org. In the case of the RoboSmart theme we have used a single grid at 600 which is fluid and works for any screen resolution greater than 600px.

Người mua thiếu niềm tin: thị trường BĐS còn bi đát

Người mua thiếu niềm tin: thị trường BĐS còn bi đát

Không như kỳ vọng của các DN BĐS về thị trường sẽ ấm trở lại từ quý II/2012, diễn biến và kết quả thực tế của thị trường trong nửa đầu năm hiện lên với nhiều giảm sút mà vẫn chưa thấy đà bật lên.

5 Facebook plugin tốt nhất nên có cho WordPress

Giới thiệu 5 Facebook plugin tốt nhất nên có cho WordPress

Không cần phải nói nhiều về Facebook – mạng xã hội lớn nhất thế giới hiện nay – với sức ảnh hưởng sâu rộng của nó. Theo ý kiến chủ quan của Việt Coding

Công ty diệt chuột T&C

 

Diet con trung