arondir nombre python code example
Example: arrondire au centième python
>>> round(3.1415)
3
>>> x = 1.4567
>>> round(x,1)
1.5
>>> x = 3.1415
>>> x = int(x)
>>> x
3
>>> type(x)
<class 'int'>
>>> x = round(3.1415)
>>> type(x)
<class 'int'>
>>> x
3
>>> import numpy as np
>>> a = np.array(([1.24,3.46,5.34]))
>>> a
array([1.24, 3.46, 5.34])
>>> np.around(a, decimals=1)
array([1.2, 3.5, 5.3])
>>> import numpy as np
>>> a = np.array(([1,24,3.46,5.34]))
>>> a
array([ 1. , 24. , 3.46, 5.34])
>>> a.astype(int)
array([ 1, 24, 3, 5])
>>> z = 2.14 + 3.47j
>>> round(z.real, 1) + round(z.imag, 1) * 1j
(2.1+3.5j)
>>> s = 'Pi value is {:06.2f}'.format(3.141592653589793)
>>> s
'Pi value is 003.14'
>>> s = 'Pi value is {:01.2f}'.format(3.141592653589793)
>>> s
'Pi value is 3.14'