RedinGhost's picture
Publish curated reproducibility artifact
598316f verified
Raw
History Blame Contribute Delete
1.69 kB
diff --git a/src/humanize/number.py b/src/humanize/number.py
index 2fb22c6..0b6a6f2 100644
--- a/src/humanize/number.py
+++ b/src/humanize/number.py
@@ -193,7 +193,12 @@ human_powers = (
)
-def intword(value: NumberOrString, format: str = "%.1f") -> str:
+def intword(
+ value: NumberOrString,
+ format: str = "%.1f",
+ *,
+ separator: str = " ",
+) -> str:
"""Converts a large integer to a friendly text representation.
Works best for numbers over 1 million. For example, 1_000_000 becomes "1.0 million",
@@ -223,6 +228,7 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
value (int, float, str): Integer to convert.
format (str): To change the number of decimal or general format of the number
portion.
+ separator (str): Text inserted between the number and scale word.
Returns:
str: Friendly text representation as a string, unless the value passed could not
@@ -230,6 +236,9 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
"""
import math
+ if not isinstance(separator, str):
+ raise TypeError("separator must be a string")
+
try:
if not math.isfinite(float(value)):
return _format_not_finite(float(value))
@@ -264,7 +273,7 @@ def intword(value: NumberOrString, format: str = "%.1f") -> str:
unit = _ngettext(singular, plural, math.ceil(rounded_value))
decimal_sep = decimal_separator()
number = (format % rounded_value).replace(".", decimal_sep)
- return f"{negative_prefix}{number} {unit}"
+ return f"{negative_prefix}{number}{separator}{unit}"
def apnumber(value: NumberOrString) -> str: