MCPcopy
hub / github.com/InstaPy/InstaPy / truncate_float

Function truncate_float

instapy/util.py:2158–2180  ·  view source on GitHub ↗

Truncate (shorten) a floating point value at given precision

(number, precision, round=False)

Source from the content-addressed store, hash-verified

2156
2157
2158def truncate_float(number, precision, round=False):
2159 """Truncate (shorten) a floating point value at given precision"""
2160
2161 # don't allow a negative precision [by mistake?]
2162 precision = abs(precision)
2163
2164 if round:
2165 # python 2.7+ supported method [recommended]
2166 short_float = round(number, precision)
2167
2168 # python 2.6+ supported method
2169 """short_float = float("{0:.{1}f}".format(number, precision))
2170 """
2171
2172 else:
2173 operate_on = 1 # returns the absolute number (e.g. 11.0 from 11.456)
2174
2175 for _ in range(precision):
2176 operate_on *= 10
2177
2178 short_float = float(int(number * operate_on)) / operate_on
2179
2180 return short_float
2181
2182
2183def get_time_until_next_month():

Callers 14

unfollowFunction · 0.85
validate_usernameFunction · 0.85
progress_trackerFunction · 0.85
follow_commentersMethod · 0.85
follow_likersMethod · 0.85
follow_by_listMethod · 0.85
follow_user_followersMethod · 0.85
follow_user_followingMethod · 0.85
live_reportMethod · 0.85
run_timeMethod · 0.85
get_followersFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected