Basic 5 · Computing · Data, Sources and Usage

Data Types: Integer, Float and Double

In this topic you will recognise basic data types used by computers, including integers, floats and doubles.

By the end of these notes you should be able to:

  • Define a data type
  • Distinguish integers from decimal numbers (float and double)
  • Classify data into the correct data type

What you already know

  • Primary and secondary sources

Copy everything that has a blue line on its left into your notebook. The other parts are for reading.

Strand
Introduction To Computing
Sub-strand
Data, Sources and Usage
Indicator
B5.1.3.1.5-7 – Recognize data types (integer, double float)

Introduction

A computer must know what kind of data it is storing. The number of pupils in a class (35) is different from a pupil's height (1.42 m). Computers store these as different data types.

1. What Is a Data Type?

Data type: The kind of value a piece of data is, which tells the computer how to store and use it.

Choosing the right data type saves memory and avoids mistakes. A computer would not store "Ama" the same way it stores 35.

2. Integers

Integer: A whole number with no decimal part. It can be positive, negative or zero.

Examples: 35, 0, −12, 2026. Integers are used for counting things such as pupils, chairs and goals scored.

3. Float and Double

Float: A number with a decimal point, stored with fewer digits of accuracy.

Double: A number with a decimal point, stored with about twice as many digits of accuracy as a float.

Examples of decimal numbers: 1.42, 36.6, 3.14159, −0.5. They are used for measurements such as height, temperature, mass and money. A float is good enough for simple measurements. A double is used when great accuracy is needed, such as in science, banking and space travel.

Comparing data types
Data typeWhat it holdsExamplesTypical use
integerwhole numbers35, −4, 0counting pupils, age in years
floatdecimals (less precise)1.5, 36.6temperature, height
doubledecimals (more precise)3.14159265358979science and money calculations
Three boxes labelled integer, float and double with example values sorted into them
Figure 1: Sorting data types Draw three boxes and sort ten numbers into them.Illustration: Sirbus

4. Other Data Types

Other common data types
TypeHoldsExample
string (text)letters and symbols"Ama", "Accra"
Booleantrue or false onlyTrue
charactera single letter or symbol"A"

Common mistake: 25.0 has a decimal point, so the computer treats it as a float, even though it equals the whole number 25.

New words

data type
The kind of value data is.
integer
A whole number.
float
A decimal number with less precision.
double
A decimal number with more precision.
precision
How many digits are stored accurately.
string
Text data.

Summary

  • A data type tells the computer what kind of value it is storing.
  • Integers are whole numbers.
  • Floats and doubles store decimal numbers; doubles are more precise.
  • Text is stored as a string.

Class activity: Data Type Sort

  1. Use number and word cards (e.g. 12, 3.5, "Kofi", −7, 98.6).
  2. Sort them into integer, float/double and string.
  3. Explain each choice.

You need: Locally made integer, Decimal cards, Data-type label cards, Manila sorting mat

Exercises

Answer in your exercise book first, then check your answers.

  1. 1. Which is an integer?

    • A. 42
    • B. 4.2
    • C. 0.42
    • D. "42.0"
    Show answer
    Answer: 42It has no decimal part.
  2. 2. Which data type is best for body temperature?

    • A. Float
    • B. Integer
    • C. Boolean
    • D. Character
    Show answer
    Answer: FloatIt has decimals.
  3. 3. Which is more precise?

    • A. Double
    • B. Float
    • C. Integer
    • D. Boolean
    Show answer
    Answer: DoubleIt stores more digits.
  4. 4. −8 is an integer.

    • A. True
    • B. False
    Show answer
    Answer: TrueIntegers can be negative.
  5. 5. 7.0 is stored as an integer.

    • A. True
    • B. False
    Show answer
    Answer: FalseThe decimal point makes it a float.
  6. 6. A whole number with no decimal part is an ______.

    Show answer
    Answer: integere.g. 35.
  7. 7. Give one example each of an integer and a float.

    Show answer
    Answer: Integer: 20 pupils; float: 1.65 m height.Any correct examples.
  8. 8. Why might a bank use double instead of float?

    Show answer
    Answer: Money calculations need high accuracy; double stores more digits so there are fewer rounding errors.Precision matters.

Homework

  1. Write ten pieces of data about yourself (age, height, name, etc.) and state the data type of each.