You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
Repository navigation
Commit 6c9a6fa
Browse filesBrowse the repository at this point in the historyBrowse files
// What it does: Pads the start of the string with "0"s until the string reaches a total length of 3 characters.
39
+
// For "399", it stays "399". However, if the input was "5p", this step would turn "5" into "005".
40
+
// Rationale: This is a safety measure for small amounts (under £1.00).
41
+
// By forcing a minimum length of 3 characters, it ensures there are always enough digits to separate into at least one digit for pounds and two digits for pence.
// What it does: Grabs everything from the start of the padded string up to the final 2 characters.
45
+
// For "399", it extracts "3". For a padded string like "005", it would extract "0".
46
+
// Rationale: Since 100 pence equals 1 pound, the last two digits of any pence value will always represent the change, and everything before those last two digits represents the whole pounds.
// What it does: This does two things. First, .substring(...) extracts exactly the last 2 characters of the string (e.g., "99" from "399").
50
+
// Then, .padEnd(2, "0") ensures it is 2 characters long by adding zeros to the right (though because of the previous steps, it's already 2 characters long here).
51
+
// Rationale: This isolates the final two digits to represent the pence column cleanly, ensuring it always displays as a standard two-digit currency format (like .05 or .99).
52
+
53
+
// console.log(\£${pounds}.${pence}`);`
54
+
// What it does: Uses a template literal to combine the pound sign (£), the pounds variable, a decimal point (.), and the pence variable into one string, printing £3.99 to the console.
55
+
// Rationale: This is the final presentation layer, formatting the separated data pieces into a human-readable UK currency format.
0 commit comments