Ask Your Question
1

convert output

asked 2014-07-31 21:30:30 +0100

Tomy gravatar image

updated 2014-07-31 21:31:05 +0100

Hello, if a function gives an output like this

2.00000000000000 - 2.77555756156289e-17*I

how could one convert it to be simply

2

Bests

edit retag flag offensive close merge delete

Comments

1

If you can give us the exact command which does this, it would be helpful. Sometimes this is a bug, and similar ones have been tracked (and fixed). Thanks!

kcrisman gravatar imagekcrisman ( 2014-08-02 03:34:45 +0100 )edit

2 Answers

Sort by » oldest newest most voted
1

answered 2014-08-04 21:05:54 +0100

niles gravatar image

The round function will give you the nearest number with a given number of digits. Note that it only works for real numbers, so you should round the real and imaginary parts separately.

If you just want to display fewer digits, but have sage remember more precision, then you can use python string formatting. See this question.

edit flag offensive delete link more
0

answered 2014-07-31 21:46:20 +0100

FrédéricC gravatar image

Maybe something like that ?

sage: QQ(real_part(2.00000000000000 - 2.77555756156289e-17*I))
2
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

1 follower

Stats

Asked: 2014-07-31 21:30:30 +0100

Seen: 763 times

Last updated: Aug 04 '14