[pyar] Obtener parte entera y parte decimal

claudio canepa ccanepacc en gmail.com
Mar Mayo 21 20:27:06 ART 2013


Si la precision no es critica me gusta el operador % :

Python 3.3.1 (v3.3.1:d9893d13c628, Apr 6 2013, 20:25:12) [MSC v.1600 32 bit
(In
tel)] on win32
>>> pi = 3.14
>>> pi % 1
0.14000000000000012
>>> 17.12345 % 1
0.12344999999999828
>>>


2013/5/21 Maxi <maxirobaina en gmail.com>

> Para obtener la parte entera y la parte decimal de un número puedo hacer:
>
> x = 26.236824093086927
>
> parte_entera = int(x)
> parte_decimal = abs(x) - abs(int(x))
>
> O usando el módulo decimal
>
> >>> from decimal import Decimal
> >>> Decimal(str(x))
> Decimal('26.2368240931')
>
> >>> Decimal(str(x)) % 1
> Decimal('0.2368240931')
>
>
> ¿Algúna otra sugerencia? ¿Hay alguna forma mejor que otra?
>
>
> Saludos.
> _______________________________________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/listinfo/pyar
>
> PyAr - Python Argentina - Sitio web: http://www.python.org.ar/
>
> La lista de PyAr esta Hosteada en USLA - Usuarios de Software Libre de
> Argentina - http://www.usla.org.ar
>
------------ próxima parte ------------
Se ha borrado un adjunto en formato HTML...
URL: <http://listas.python.org.ar/pipermail/pyar/attachments/20130521/f00c58c7/attachment.html>


More information about the pyar mailing list