Published by Patrick Mutisya · 14 days ago
Be able to set sub‑types of numeric data, including percentage and the number of decimal places, when designing or modifying a database table.
Sub‑types control how numeric values are stored, displayed and validated. Choosing the correct sub‑type ensures:
Most database packages (e.g., Microsoft Access, LibreOffice Base) allow you to specify a field as a Number with the sub‑type Percentage. The field stores the value as a decimal fraction but displays it with a percent sign.
Number.Percentage.0.00%).Example
If a user enters 85 in a percentage field, the database stores it as 0.85. When displayed, it appears as 85%. Calculations use the stored decimal value, so a query that multiplies a price by a discount percentage works correctly:
\$\text{Discounted Price}= \text{Original Price} \times (1 - \text{Discount\%})\$
For a price of $120 and a discount of 15%, the calculation is:
\$120 \times (1 - 0.15) = 120 \times 0.85 = 102\$
When a field must retain a fixed number of decimal places (e.g., monetary values), set the sub‑type to Decimal and define the format.
Number.Decimal (or Fixed‑point depending on the software).0.00 for two places.Example
A field for “Unit Price” is set to two decimal places. Entering 3.5 is automatically displayed as 3.50. Calculations such as total cost use the stored value 3.50:
\$\text{Total Cost}= \text{Unit Price} \times \text{Quantity}\$
If the quantity is 4, the total cost is:
\$3.50 \times 4 = 14.00\$
| Sub‑type | Display Format | Typical Use | Example Input / Stored \cdot alue |
|---|---|---|---|
| Integer | Whole number (no decimals) | Counts, IDs, ages | Input: 27 Stored: 27 |
| Decimal (Fixed‑point) | Fixed number of decimal places (e.g., 0.00) | Money, measurements | Input: 12.5 Stored: 12.50 |
| Floating‑point | Variable decimals, scientific notation possible | Large calculations, scientific data | Input: 0.000123 Stored: 1.23E‑4 |
| Percentage | Number shown with % sign (e.g., 85%) | Discounts, rates, statistics | Input: 85 Stored: 0.85 |
123.456.12.5%?