本文整理汇总了Python中mo_math.Math.abs方法的典型用法代码示例。如果您正苦于以下问题:Python Math.abs方法的具体用法?Python Math.abs怎么用?Python Math.abs使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类mo_math.Math
的用法示例。
在下文中一共展示了Math.abs方法的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Python代码示例。
示例1: __unicode__
# 需要导入模块: from mo_math import Math [as 别名]
# 或者: from mo_math.Math import abs [as 别名]
def __unicode__(self):
if not self.milli:
return "zero"
output = ""
rest = (self.milli - (MILLI_VALUES.month * self.month)) # DO NOT INCLUDE THE MONTH'S MILLIS
isNegative = (rest < 0)
rest = Math.abs(rest)
# MILLI
rem = rest % 1000
if rem != 0:
output = "+" + text_type(rem) + "milli" + output
rest = Math.floor(rest / 1000)
# SECOND
rem = rest % 60
if rem != 0:
output = "+" + text_type(rem) + "second" + output
rest = Math.floor(rest / 60)
# MINUTE
rem = rest % 60
if rem != 0:
output = "+" + text_type(rem) + "minute" + output
rest = Math.floor(rest / 60)
# HOUR
rem = rest % 24
if rem != 0:
output = "+" + text_type(rem) + "hour" + output
rest = Math.floor(rest / 24)
# DAY
if (rest < 11 and rest != 7) or rest % 10 == 0:
rem = rest
rest = 0
else:
rem = rest % 7
rest = Math.floor(rest / 7)
if rem != 0:
output = "+" + text_type(rem) + "day" + output
# WEEK
if rest != 0:
output = "+" + text_type(rest) + "week" + output
if isNegative:
output = output.replace("+", "-")
# MONTH AND YEAR
if self.month:
sign = "-" if self.month < 0 else "+"
month = Math.abs(self.month)
if month <= 18 and month != 12:
output = sign + text_type(month) + "month" + output
else:
m = month % 12
if m != 0:
output = sign + text_type(m) + "month" + output
y = Math.floor(month / 12)
output = sign + text_type(y) + "year" + output
if output[0] == "+":
output = output[1::]
if output[0] == '1' and not Math.is_number(output[1]):
output = output[1::]
return output