From 304ddd8114e12f4fdd5057dc933a2981bd9e1ec7 Mon Sep 17 00:00:00 2001 From: Bnyro Date: Sat, 20 Jul 2024 21:27:12 +0200 Subject: [feat] videos template: support for view count --- searx/utils.py | 12 ++++++++++++ 1 file changed, 12 insertions(+) (limited to 'searx/utils.py') diff --git a/searx/utils.py b/searx/utils.py index 191161bde..407d44cd0 100644 --- a/searx/utils.py +++ b/searx/utils.py @@ -334,6 +334,18 @@ def humanize_bytes(size, precision=2): return "%.*f %s" % (precision, size, s[p]) +def humanize_number(size, precision=0): + """Determine the *human readable* value of a decimal number.""" + s = ['', 'K', 'M', 'B', 'T'] + + x = len(s) + p = 0 + while size > 1000 and p < x: + p += 1 + size = size / 1000.0 + return "%.*f%s" % (precision, size, s[p]) + + def convert_str_to_int(number_str: str) -> int: """Convert number_str to int or 0 if number_str is not a number.""" if number_str.isdigit(): -- cgit v1.2.3-54-g00ecf