# decimal form of a unit converted answer

I was wondering what a good way might be to get a decimal answer when using units. For example, say I try

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3*ft + 4*m).convert(units.length.ft)


I get back

6143/381*foot


Now, suppose I'd rather see this represented as a decimal than a fraction (for homework, perhaps?). If I try

(3*ft + 4*m).convert(units.length.foot).n()


I get an error. This is occuring on Sage 4.8 for sure, and I'm pretty sure in Sage 5.0 as well.

Can anyone think of a good solution to this?

edit retag close merge delete

Sort by ยป oldest newest most voted

It is better to write the units to convert in decimal form

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3.0*ft+4.0*m).convert(units.length.foot)

more

wow, do i feel dumb. i can't believe it didn't occur to me to try that. thank you.

( 2012-05-20 18:20:58 -0500 )edit

Not dumb at all, especially if you haven't used that much yet. I would say that this still smells like a bug.

( 2012-05-21 03:26:45 -0500 )edit

There is actually a way to do this; see here.

#define units
ft =  units.length.foot
m = units.length.meter
#add some lengths and output in ft
(3*ft + 4*m).convert(units.length.foot).polynomial(RR)


This returns

16.1233595800525*foot

more