SECTION 12 / 13

Transform representations: dates, fractional marks and money

3 min read
On this page 4 headings

The way a value is displayed need not be the way it is stored. A useful representation makes the required comparisons and calculations easier, while a display operation converts it back to human-readable form.

Bhuvanesh’s mark can be represented as 68 out of 100 or 6,800 out of 10,000.
Bhuvanesh’s mark can be represented as 68 out of 100 or 6,800 out of 10,000.
YOUR COURSE DATA · TRY IT HERE

Convert marks out of 100 to marks out of 10,000

Use the supplied 30 score cards. No download or coding is needed.

READY TO START

A pile of 30 cards

Start with the first card. Read its fields, do one small action, then move on.

What we remember

Read
0

Nothing has been read yet. Choose Next card to begin.

Look through all 30 original records
BhuvaneshMaths 68 · Erode
CardNo
0
Name
Bhuvanesh
Gender
M
DateOfBirth
7 Nov
CityTown
Erode
Mathematics
68
Physics
64
Chemistry
78
Total
210
HarishMaths 62 · Salem
CardNo
1
Name
Harish
Gender
M
DateOfBirth
3 Jun
CityTown
Salem
Mathematics
62
Physics
45
Chemistry
91
Total
198
ShashankMaths 57 · Chennai
CardNo
2
Name
Shashank
Gender
M
DateOfBirth
4 Jan
CityTown
Chennai
Mathematics
57
Physics
54
Chemistry
77
Total
188
RidaMaths 42 · Chennai
CardNo
3
Name
Rida
Gender
F
DateOfBirth
5 May
CityTown
Chennai
Mathematics
42
Physics
53
Chemistry
78
Total
173
RitikaMaths 87 · Madurai
CardNo
4
Name
Ritika
Gender
F
DateOfBirth
17 Nov
CityTown
Madurai
Mathematics
87
Physics
64
Chemistry
89
Total
240
AkshayaMaths 71 · Chennai
CardNo
5
Name
Akshaya
Gender
F
DateOfBirth
8 Feb
CityTown
Chennai
Mathematics
71
Physics
92
Chemistry
84
Total
247
SameerMaths 81 · Ambur
CardNo
6
Name
Sameer
Gender
M
DateOfBirth
23 Mar
CityTown
Ambur
Mathematics
81
Physics
82
Chemistry
87
Total
250
AdityaMaths 84 · Vellore
CardNo
7
Name
Aditya
Gender
M
DateOfBirth
15 Mar
CityTown
Vellore
Mathematics
84
Physics
92
Chemistry
76
Total
252
SuryaMaths 74 · Bengaluru
CardNo
8
Name
Surya
Gender
M
DateOfBirth
28 Feb
CityTown
Bengaluru
Mathematics
74
Physics
64
Chemistry
51
Total
189
ClarenceMaths 63 · Bengaluru
CardNo
9
Name
Clarence
Gender
M
DateOfBirth
6 Dec
CityTown
Bengaluru
Mathematics
63
Physics
88
Chemistry
73
Total
224
KavyaMaths 64 · Chennai
CardNo
10
Name
Kavya
Gender
F
DateOfBirth
12 Jan
CityTown
Chennai
Mathematics
64
Physics
72
Chemistry
68
Total
204
RahulMaths 97 · Bengaluru
CardNo
11
Name
Rahul
Gender
M
DateOfBirth
30 Apr
CityTown
Bengaluru
Mathematics
97
Physics
92
Chemistry
92
Total
281
SrinidhiMaths 52 · Chennai
CardNo
12
Name
Srinidhi
Gender
F
DateOfBirth
14 Jan
CityTown
Chennai
Mathematics
52
Physics
64
Chemistry
71
Total
187
GopiMaths 65 · Madurai
CardNo
13
Name
Gopi
Gender
M
DateOfBirth
6 May
CityTown
Madurai
Mathematics
65
Physics
73
Chemistry
89
Total
227
SophiaMaths 89 · Trichy
CardNo
14
Name
Sophia
Gender
F
DateOfBirth
23 July
CityTown
Trichy
Mathematics
89
Physics
62
Chemistry
93
Total
244
GoutamiMaths 76 · Theni
CardNo
15
Name
Goutami
Gender
F
DateOfBirth
22 Sep
CityTown
Theni
Mathematics
76
Physics
58
Chemistry
90
Total
224
TauseefMaths 87 · Trichy
CardNo
16
Name
Tauseef
Gender
M
DateOfBirth
30 Dec
CityTown
Trichy
Mathematics
87
Physics
86
Chemistry
43
Total
216
ArshadMaths 62 · Chennai
CardNo
17
Name
Arshad
Gender
M
DateOfBirth
14 Dec
CityTown
Chennai
Mathematics
62
Physics
81
Chemistry
67
Total
210
AbiramiMaths 72 · Erode
CardNo
18
Name
Abirami
Gender
F
DateOfBirth
9 Oct
CityTown
Erode
Mathematics
72
Physics
92
Chemistry
97
Total
261
VetrivelMaths 56 · Trichy
CardNo
19
Name
Vetrivel
Gender
M
DateOfBirth
30 Aug
CityTown
Trichy
Mathematics
56
Physics
78
Chemistry
62
Total
196
KalyanMaths 93 · Vellore
CardNo
20
Name
Kalyan
Gender
M
DateOfBirth
17 Sep
CityTown
Vellore
Mathematics
93
Physics
68
Chemistry
91
Total
252
MonikaMaths 78 · Bengaluru
CardNo
21
Name
Monika
Gender
F
DateOfBirth
15 Mar
CityTown
Bengaluru
Mathematics
78
Physics
69
Chemistry
74
Total
221
PriyaMaths 62 · Nagercoil
CardNo
22
Name
Priya
Gender
F
DateOfBirth
17 Jul
CityTown
Nagercoil
Mathematics
62
Physics
62
Chemistry
57
Total
181
DeepikaMaths 97 · Bengaluru
CardNo
23
Name
Deepika
Gender
F
DateOfBirth
13 May
CityTown
Bengaluru
Mathematics
97
Physics
91
Chemistry
88
Total
276
SiddharthMaths 44 · Madurai
CardNo
24
Name
Siddharth
Gender
M
DateOfBirth
26 Dec
CityTown
Madurai
Mathematics
44
Physics
72
Chemistry
58
Total
174
GeetaMaths 87 · Chennai
CardNo
25
Name
Geeta
Gender
F
DateOfBirth
16 May
CityTown
Chennai
Mathematics
87
Physics
75
Chemistry
92
Total
254
JKMaths 74 · Chennai
CardNo
26
Name
JK
Gender
M
DateOfBirth
22 Jul
CityTown
Chennai
Mathematics
74
Physics
71
Chemistry
82
Total
227
JaganMaths 81 · Madurai
CardNo
27
Name
Jagan
Gender
M
DateOfBirth
4 Mar
CityTown
Madurai
Mathematics
81
Physics
76
Chemistry
52
Total
209
NishaMaths 74 · Madurai
CardNo
28
Name
Nisha
Gender
F
DateOfBirth
10 Sep
CityTown
Madurai
Mathematics
74
Physics
83
Chemistry
83
Total
240
NaveenMaths 72 · Vellore
CardNo
29
Name
Naveen
Gender
M
DateOfBirth
13 Oct
CityTown
Vellore
Mathematics
72
Physics
66
Chemistry
81
Total
219
Date indices and hundredths-based values are integers internally, with a defined conversion back for display.
Date indices and hundredths-based values are integers internally, with a defined conversion back for display.

Represent a date as its day index

The lecture uses 1 January = 0, 2 January = 1, 31 January = 30 and 1 February = 31. For a fixed non-leap year, valid day indices run 0–364. In a leap year they run 0–365. You need a consistent year/calendar convention, especially for 29 February and dates after February.

With that convention, compare dates by comparing their integer indices. Convert the index to a date string for display: print(31) produces “1 Feb”. Adding a number of days to a date or taking a difference between dates can be meaningful with boundary rules; adding two calendar dates is not automatically meaningful just because both are stored as integers.

Keep two decimal places by scaling

If marks have at most two decimal places, multiply by 100 and store integer hundredths. 62.5 becomes 6250, and 75.25 becomes 7525. To display, divide the scale back out. Single-subject marks 0–100 therefore need stored integers 0–10000, as corrected in the supplied slides.

Human valueStore ×100Display
62.50 marks625062.50 marks
75.25 marks752575.25 marks
Rs 27.502750Rs 27.50
1.25 kg1251.25 kg
100 marks10000100.00 marks

Preserve the scale during operations

Add or compare values only after confirming compatible scales and units. Stored marks 6250+7525 = 13775 represent 137.75 total marks; that result requires a total type wider than single-subject Marks. Stored amounts Rs 27.50 and Rs 12.25 add as 2750+1225 = 3975 paise, displayed Rs 39.75.

If both quantity and price are scaled by 100, multiplying their stored integers creates a scale of 10,000. For 1.25 kg at Rs 20.00 per kg, 125×2000 = 250000 hundredths-of-hundredths. Divide by 100 to obtain 2500 paise, displayed Rs 25.00. State the rescaling and any rounding rule. Do not interpret 250000 as paise directly.

Why not drop the fractional part?

Turning 62.5 into 62 or 63 loses information and can affect comparisons. A floating-point type is another option, but it has finite precision; it does not store arbitrary real numbers exactly. The lesson’s fixed-scale representation is especially simple when the allowed decimal precision is known.

Try it yourself

How is 48.75 stored using hundredths, and how is stored 1250 displayed?

Show explained answer

48.75 is stored as 4875. Stored 1250 represents 12.50 when the scale is 100.

Try it yourself

What is the largest stored integer for one mark out of 100 at scale 100?

Show explained answer

100×100 = 10000. A maximum of 1000 would only reach 10.00, so it is too small.

Try it yourself

With 1 Jan = 0, what index represents 2 February in the same year?

Show explained answer

32. January contributes 31 days; 1 February is 31, so 2 February is 32.

Try it yourself

Why should stored 125 from Quantity not be blindly added to stored 125 from Amount?

Show explained answer

Their meanings and units differ. The first may mean 1.25 kg; the second may mean Rs 1.25. Equal integer representations do not make the quantities compatible.

Source: Lecture 1.9 — Transformation of sub-datatypes. Small teaching datasets and diagrams are prepared for these notes; lecture and tutorial totals are identified explicitly.

YOUR STUDY PROGRESS

Finished this section? Save your progress.

Back to top ↑