I am displaying a calculation on a page, where the result is either a single digit or double digit number. However, I want to always show two place values. Example below.
1 should be shown as 01
8 should be shown as 08
19 should be shown as 19
Is there a way to format the result so that a single digit will have a leading 0?
Well… there’s no such thing as the number 01 (that’s just the number 1)….
But if you’re want to to display a single digit number as a two character text, one simple way is to start with the character ‘0’ then append your number.
Then truncate from end to 2.
That way the number 1 will be appended to 0 to output 01, and the number 14 will be written as 014, truncated from end to 2, which will output 14.