Mapytex/mapytex/stat/number_tools.py

28 lines
572 B
Python
Raw Permalink Normal View History

2019-10-13 19:01:31 +00:00
# /usr/bin/env python
2016-01-09 15:40:02 +00:00
# -*- coding:Utf-8 -*-
from functools import wraps
def number_factory(fun):
""" Decorator which format returned value """
2019-10-13 19:01:31 +00:00
2016-01-09 15:40:02 +00:00
@wraps(fun)
def wrapper(*args, **kwargs):
ans = fun(*args, **kwargs)
try:
if ans.is_integer():
return int(ans)
else:
return round(ans, 2)
except AttributeError:
return ans
2019-10-13 19:01:31 +00:00
2016-01-09 15:40:02 +00:00
return wrapper
# -----------------------------
# Reglages pour 'vim'
# vim:set autoindent expandtab tabstop=4 shiftwidth=4:
2016-02-13 03:29:26 +00:00
# cursor: 16 del