ASKSAGE: Sage Q&A Forum - RSS feedhttps://ask.sagemath.org/questions/Q&A Forum for SageenCopyright Sage, 2010. Some rights reserved under creative commons license.Wed, 11 Nov 2015 18:43:53 +0100How to keep my real numbers roundedhttps://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/The following code:
var('t')
test(x) = e^(x * t)
test(0.326)
gives:
e^(0.326000000000000*t)
For some reason, Sage converted my "0.326" to "0.326000000000000".
I want to keep the number rounded. i.e:
e^(0.326*t)
I don't even care if Sage rounds it like this:
e^(0.33*t)
How can I do this?
I know it is possible to use fractions, E.g, I can use "326/1000" instead of "0.326", but this doesn't look good. All I want is that the floating point numbers remain rounded.
Mon, 09 Nov 2015 18:44:41 +0100https://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/Answer by FrédéricC for <p>The following code:</p>
<pre><code>var('t')
test(x) = e^(x * t)
test(0.326)
</code></pre>
<p>gives:</p>
<pre><code>e^(0.326000000000000*t)
</code></pre>
<p>For some reason, Sage converted my "0.326" to "0.326000000000000". </p>
<p>I want to keep the number rounded. i.e:</p>
<pre><code>e^(0.326*t)
</code></pre>
<p>I don't even care if Sage rounds it like this:</p>
<pre><code>e^(0.33*t)
</code></pre>
<p>How can I do this?</p>
<p>I know it is possible to use fractions, E.g, I can use "326/1000" instead of "0.326", but this doesn't look good. All I want is that the floating point numbers remain rounded.</p>
https://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/?answer=30601#post-id-30601Maybe like that
sage: myR=RealField(12)
sage: var('t')
t
sage: test(x) = e^(x * t)
sage: test(myR(0.326))
e^(0.326*t)
Mon, 09 Nov 2015 19:10:52 +0100https://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/?answer=30601#post-id-30601Comment by Erel Segal-Halevi for <p>Maybe like that</p>
<pre><code>sage: myR=RealField(12)
sage: var('t')
t
sage: test(x) = e^(x * t)
sage: test(myR(0.326))
e^(0.326*t)
</code></pre>
https://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/?comment=30636#post-id-30636OK. So I have to convert each real number to the field "real number with 12 bit precision"?Wed, 11 Nov 2015 18:43:53 +0100https://ask.sagemath.org/question/30599/how-to-keep-my-real-numbers-rounded/?comment=30636#post-id-30636