Ask Your Question
2

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

asked 2016-03-30 04:10:36 +0100

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
3

answered 2016-03-31 11:07:22 +0100

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 15:30:38 +0100 )edit
1

answered 2016-03-31 09:42:16 +0100

slelievre gravatar image

updated 2016-03-31 09:57:43 +0100

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-30 04:09:23 +0100

Seen: 9,713 times

Last updated: Mar 31 '16