File size: 1,217 Bytes
598316f
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
diff --git a/src/humanize/number.py b/src/humanize/number.py
index 2fb22c6..201702e 100644
--- a/src/humanize/number.py
+++ b/src/humanize/number.py
@@ -501,7 +501,13 @@ def clamp(
     raise ValueError(msg)
 
 
-def metric(value: float, unit: str = "", precision: int = 3) -> str:
+def metric(
+    value: float,
+    unit: str = "",
+    precision: int = 3,
+    *,
+    ascii_only: bool = False,
+) -> str:
     """Return a value with a metric SI unit-prefix appended.
 
     Examples:
@@ -532,6 +538,7 @@ def metric(value: float, unit: str = "", precision: int = 3) -> str:
         value (int, float): Input number.
         unit (str): Optional base unit.
         precision (int): The number of digits the output should contain.
+        ascii_only (bool): Render the micro prefix as ``u`` instead of ``μ``.
 
     Returns:
         str:
@@ -560,6 +567,8 @@ def metric(value: float, unit: str = "", precision: int = 3) -> str:
         ordinal_ = "mμnpfazyrq"[(-exponent - 1) // 3]
     else:
         ordinal_ = ""
+    if ascii_only and ordinal_ == "μ":
+        ordinal_ = "u"
     value_ = format(value, f".{digits}f")
     if not (unit or ordinal_) or unit in ("°", "′", "″"):
         space = ""