Decimal, Float or Integer in 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:
- Decimal
- Float
- Integer
- List (float)
- 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:
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:
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:
Things such as spaces, commas or decimal points are added from the Manage Display tab:
Decimal
The Decimal field allows numbers with fractions.
You can decide on three settings for the field, including:
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.
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:
Things such as spaces, commas or decimal points are added from the Manage Display tab:
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/
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.
The Manage Display settings are the same as for Decimal.
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.
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.
If you choose "Select list", then this is how the options will show:
No comments:
Post a Comment