Title: RE: A rational proposal

[Mike Meyer]

#- Good point. Currently, objects now how to convert themselves to int,
#- float and complex. Should Rational now how to convert itself to
#- Decimal (and conversely, decimal now how to convert itself to
#- Rational)?

To convert a Decimal to Rational, just take the number and divide it by 1E+n:

  Decimal(5) -> Rational(5)
  Decimal("5.35") -> Rational(535, 100)

To convert a Rational to a Decimal, it would be a good idea to have a method that converts the Rational to a Decimal string...

  Rational(5).tostring(6) -> "5.00000"
  Rational(4, 5).tostring(3) -> "0.80"
  Rational(5321351343, 2247313131).tostring(5000) -> whatever

... and then take that string as input to Decimal and it will work.


.    Facundo

Bitácora De Vuelo: http://www.taniquetil.com.ar/plog
PyAr - Python Argentina: http://pyar.decode.com.ar/


. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . .

ADVERTENCIA.

La información contenida en este mensaje y cualquier archivo anexo al mismo, son para uso exclusivo del destinatario y pueden contener información confidencial o propietaria, cuya divulgación es sancionada por la ley.

Si Ud. No es uno de los destinatarios consignados o la persona responsable de hacer llegar este mensaje a los destinatarios consignados, no está autorizado a divulgar, copiar, distribuir o retener información (o parte de ella) contenida en este mensaje. Por favor notifíquenos respondiendo al remitente, borre el mensaje original y borre las copias (impresas o grabadas en cualquier medio magnético) que pueda haber realizado del mismo.

Todas las opiniones contenidas en este mail son propias del autor del mensaje y no necesariamente coinciden con las de Telefónica Comunicaciones Personales S.A. o alguna empresa asociada.

Los mensajes electrónicos pueden ser alterados, motivo por el cual Telefónica Comunicaciones Personales S.A. no aceptará ninguna obligación cualquiera sea el resultante de este mensaje.

Muchas Gracias.

-- 
http://mail.python.org/mailman/listinfo/python-list

Reply via email to