def trunc(x: int|float) -> int
x
.
Truncates the Real x to the nearest Integral toward 0. Uses the __trunc__ magic method.
Paramètre | Description |
---|---|
x : int|float |
un nombre flottant pour lequel la partie entière doit être extraite. |
La valeur de retour est de type int|float.
Elle correspond à la partie entière du nombre flottant x
.
TypeError :Une exception de ce type sera déclenchée si le paramètre
x
ne contient pas une valeur numérique (entière ou floattante).
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 |
#!/usr/bin/python3 import math value = 4.7 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = 4.1 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = 4.0 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = 0 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = -1.3 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = -1.9 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) value = -2 print("Math.trunc( %.1f ) == %d" % (value, math.trunc(value))) |
Et voici les résultats produits par cet exemple.
$> python sample.py Math.trunc( 4.7 ) == 4 Math.trunc( 4.1 ) == 4 Math.trunc( 4.0 ) == 4 Math.trunc( 0.0 ) == 0 Math.trunc( -1.3 ) == -1 Math.trunc( -1.9 ) == -1 Math.trunc( -2.0 ) == -2 $>
Améliorations / Corrections
Vous avez des améliorations (ou des corrections) à proposer pour ce document : je vous remerçie par avance de m'en faire part, cela m'aide à améliorer le site.
Emplacement :
Description des améliorations :