Feature Request
Dennis Lee Bieber
wlfraed at ix.netcom.com
Wed Mar 23 11:55:06 EDT 2022
On Wed, 23 Mar 2022 01:55:37 -0700 (PDT), Kazuya Ito
<kazya.ito.dream at gmail.com> declaimed the following:
>Add "trun()" function to Python to truncate decimal part.
You'll have to define what specific behavior you think is missing from
the currently available functions?
>>> plusover = 2.78
>>> plusunder = 3.14
>>> minusover = -2.78
>>> minusunder = -3.14
>>> import math
>>> for v in (plusover, plusunder, minusover, minusunder):
... print("%s: int %s, round %s, math.trunc %s, math.floor %s,
math.ceil %s"
... % (v, int(v), round(v), math.trunc(v), math.floor(v),
math.ceil(v)))
...
2.78: int 2, round 3, math.trunc 2, math.floor 2, math.ceil 3
3.14: int 3, round 3, math.trunc 3, math.floor 3, math.ceil 4
-2.78: int -2, round -3, math.trunc -2, math.floor -3, math.ceil -2
-3.14: int -3, round -3, math.trunc -3, math.floor -4, math.ceil -3
>>>
int() and .trunc() move toward 0, .floor() moves to less positive,
.ceil() moves to more positive.
--
Wulfraed Dennis Lee Bieber AF6VN
wlfraed at ix.netcom.com http://wlfraed.microdiversity.freeddns.org/
More information about the Python-list
mailing list