"""@author: zhangjun.xue @time: 2020/5/25 17:46 @file: str_of_num.""
import traceback
from loguru import logger
def str_of_num(num):
' ''Recursive implementation, exact maximum unit value + three decimal places'' '
def strofsize(num, level):
if level >= 2:
return num, level
elif num >= 10000:
num /= 10000
level += 1
return strofsize(num, level)
else:
return num, level
units = [' '.'万'.'亿']
num, level = strofsize(num, 0)
if level > len(units):
level -= 1
return '{} {}'.format(round(num, 3), units[level])
def seconds_to_hms(seconds_num):
""Param: seconds_num INTEGER 666 return: HMS STR 00:00:00 param: seconds_num integer 666 return: HMS STR 00:00:00""
try:
m, s = divmod(seconds_num, 60)
h, m = divmod(m, 60)
hms = "%02d:%02d:%02d" % (h, m, s)
return hms
except:
logger.info(traceback.format_exc())
return seconds_num
if __name__ == "__main__":
num_list = [
0.1.2.10.11.100.123.1000.1234.10000.11923.5463443.54634434.97736213623.977362136234.9773621362345.97736213623456
]
for num in num_list:
str_num = str_of_num(num)
logger.info(f"num = {num} | str_num = {str_num}")
logger.info(The '-'*50.'\n')
seconds_num_list = [
10.59.60.61.71.120.121.3600.3666.3667.7200.7201.7361.86400.86460.86461.86466.Awesome!.0
]
for seconds_num in seconds_num_list:
hms = seconds_to_hms(seconds_num)
logger.info(f"seconds_num = {seconds_num} | hms = {hms}")
Copy the code