Ask Your Question
1

Show full (non-scientific-notation) of very small decimal?

asked 2016-03-29 21:10:36 -0500

notfed gravatar image

When I run:

1/(2^70).n()

Sage returns:

8.47032947254300e-22

How can I get it to instead show:

.000000000000000000000847032947254300
edit retag flag offensive close merge delete

2 answers

Sort by ยป oldest newest most voted
1

answered 2016-03-31 04:07:22 -0500

tmonteil gravatar image

You can look at the no_sci option of the str method of a floating-point number:

sage: a = 1/(2^70).n()
sage: a
8.47032947254300e-22
sage: a.str(no_sci=2)
'0.000000000000000000000847032947254300'

To get the doc of the str method, you can do a.str?

edit flag offensive delete link more

Comments

Wow, I never knew about this!

kcrisman gravatar imagekcrisman ( 2016-03-31 08:30:38 -0500 )edit
1

answered 2016-03-31 02:42:16 -0500

updated 2016-03-31 02:57:43 -0500

One possibility to get what you want is to use Python string formatting.

This can be done the old way with % and the new way with {}and .format. The old way will accept many types of numbers, the new way requires the entry to have the type of a Python float.

Here is an illustration of both, with 72 digits after the decimal point.

sage: a = 1/2^70
sage: '%.72f' % a
'0.000000000000000000000847032947254300339068322500679641962051391601562500'
sage: '{:.72f}'.format(float(a))
'0.000000000000000000000847032947254300339068322500679641962051391601562500'

Combine with print to get those displayed without the surrounding ' quotes.

sage: a = 1/2^70
sage: aa = '%.72f' % a
sage: print(aa)
0.000000000000000000000847032947254300339068322500679641962051391601562500
sage: ab = '{:.72f}'.format(float(a))
sage: print(ab)
0.000000000000000000000847032947254300339068322500679641962051391601562500

Related reading:

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: 2016-03-29 21:09:23 -0500

Seen: 106 times

Last updated: Mar 31 '16