[pyar] Obtener parte entera y parte decimal

Daniel Moisset dmoisset en machinalis.com
Mar Mayo 21 20:40:39 ART 2013


Eso te da el mismo resultado para 26.5 que para 26.00005
 On May 21, 2013 8:27 PM, "Sergio D. Gómez" <sergiogomez en tostado.com.ar>
wrote:

> On Tue, 21 May 2013 20:16:19 -0300, Maxi wrote:
>
>> 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?
>>
>>
>>
> Y algo así?
> x = 26.236824093086927
> b = str(x).split(".")
> parte_entera = int(b[0])
> parte_decimal = int(b[1])
>
> aunque en ese caso te quedarían dos enteros u no un entero y un decimal.
> Saludos.
>
> ______________________________**_________________
> pyar mailing list pyar en python.org.ar
> http://listas.python.org.ar/**listinfo/pyar<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/c9e64899/attachment.html>


More information about the pyar mailing list