Ask Your Question
0

decimal form of a unit converted answer

asked 2012-05-20 17:52:06 +0100

anonymous user

Anonymous

updated 2012-05-20 19:16:45 +0100

Shashank gravatar image

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 flag offensive close merge delete

2 Answers

Sort by » oldest newest most voted
1

answered 2012-05-20 19:19:19 +0100

Shashank gravatar image

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)
edit flag offensive delete link more

Comments

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

Arrgh_Jay gravatar imageArrgh_Jay ( 2012-05-21 01:20:58 +0100 )edit

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

kcrisman gravatar imagekcrisman ( 2012-05-21 10:26:45 +0100 )edit
1

answered 2012-05-28 20:32:53 +0100

Eviatar Bach gravatar image

updated 2012-05-28 20:33:41 +0100

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
edit flag offensive delete link more

Your Answer

Please start posting anonymously - your entry will be published after you log in or create a new account.

Add Answer

Question Tools

Stats

Asked: 2012-05-20 17:52:06 +0100

Seen: 991 times

Last updated: May 28 '12