Skip to content

Commit 02a9c9d

Browse files
committed
Added + to formatting
1 parent 05d0ea4 commit 02a9c9d

File tree

2 files changed

+9
-3
lines changed

2 files changed

+9
-3
lines changed

datahub/core/test/test_utils.py

+1-1
Original file line numberDiff line numberDiff line change
@@ -203,8 +203,8 @@ def test_format_currency_range_string_separator(string, expected):
203203
('0-9999', False, False, '£0 to £9,999'),
204204
('0-10000', False, False, '£0 to £10,000'),
205205
('0-1000000', False, False, '£0 to £1 million'),
206+
('10000001+', False, False, '£10 million+'),
206207
# Return string as Sentence case for invalid numbers
207-
('10000001+', False, False, '10000001+'),
208208
('SPECIFIC_AMOUNT', False, False, 'Specific amount'),
209209
),
210210
)

datahub/core/utils.py

+8-2
Original file line numberDiff line numberDiff line change
@@ -132,7 +132,9 @@ def format_currency_range_string(
132132
symbol='£',
133133
):
134134
"""
135-
Formats a range of ammounts according to Gov UK style guide
135+
Formats a range of ammounts according to Gov UK style guide.
136+
Note only numbers in specific formats are formatted, it doesn't detect number values within
137+
a string of mixed numbers and text.
136138
string: (string) the string containing the range to convert
137139
separator: (string) separator to use.
138140
more_or_less: (boolean) when true a range starting with 0 will be replace with Less than.
@@ -145,6 +147,7 @@ def format_currency_range_string(
145147
"""
146148
try:
147149
prefix = ''
150+
postfix = ''
148151
if more_or_less:
149152
if string[-1] == '+':
150153
prefix = 'More than '
@@ -155,8 +158,11 @@ def format_currency_range_string(
155158
values[1] = int(values[1]) + 1
156159
return f'Less than {format_currency(values[1], symbol=symbol)}'
157160
else:
161+
if string[-1] == '+':
162+
postfix = '+'
163+
string = string.rstrip('+')
158164
values = string.split(separator)
159-
return f'{prefix}{format_currency_range(values, symbol=symbol)}'
165+
return f'{prefix}{format_currency_range(values, symbol=symbol)}{postfix}'
160166
except ValueError:
161167
return upper_snake_case_to_sentence_case(string, glue='\n')
162168

0 commit comments

Comments
 (0)