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.Tue, 13 Dec 2016 03:00:28 +0100Decimal places in sliderhttps://ask.sagemath.org/question/8496/decimal-places-in-slider/Suppose you have a slider with given stepsize, say 0.1 like this
@interact
def _(a=slider(1,100,0.1)):
print a
Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place?
Sat, 19 Nov 2011 17:54:50 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/Comment by sagefan for <p>Suppose you have a slider with given stepsize, say 0.1 like this</p>
<pre><code>@interact
def _(a=slider(1,100,0.1)):
print a
</code></pre>
<p>Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place? </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20852#post-id-20852If I set the steps to 0.03 I want 2 decimal places and so on. However it would be sufficient to adjust this independently of the step-size. Just say "I want n-decimal places"...Sun, 20 Nov 2011 03:29:30 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20852#post-id-20852Comment by GĂ¶khan Sever for <p>Suppose you have a slider with given stepsize, say 0.1 like this</p>
<pre><code>@interact
def _(a=slider(1,100,0.1)):
print a
</code></pre>
<p>Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place? </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20849#post-id-20849The same question asked at http://ask.sagemath.org/question/800/interact-variable-print-formattingSun, 20 Nov 2011 23:27:26 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20849#post-id-20849Comment by Jason Grout for <p>Suppose you have a slider with given stepsize, say 0.1 like this</p>
<pre><code>@interact
def _(a=slider(1,100,0.1)):
print a
</code></pre>
<p>Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place? </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20857#post-id-20857Would that just print the number with one decimal place, even though the actual number is not that? Or do you want the actual number to be what is displayed?Sat, 19 Nov 2011 20:36:04 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20857#post-id-20857Answer by benjaminfjones for <p>Suppose you have a slider with given stepsize, say 0.1 like this</p>
<pre><code>@interact
def _(a=slider(1,100,0.1)):
print a
</code></pre>
<p>Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place? </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?answer=12921#post-id-12921As it is currently implemented, I don't believe `slider` has such an option to change the format of the displayed value. It would be a pretty easy project for a beginner to add this functionality to Sage. I could imagine changing the code in `interact.py` so that the `display_value` option could be passed a format like `"%.1f"` to indicate to display 1 decimal point.
I think that would be a valuable contribution, I would certainly use it in my interact demos. Sat, 19 Nov 2011 18:30:46 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?answer=12921#post-id-12921Comment by kcrisman for <p>As it is currently implemented, I don't believe <code>slider</code> has such an option to change the format of the displayed value. It would be a pretty easy project for a beginner to add this functionality to Sage. I could imagine changing the code in <code>interact.py</code> so that the <code>display_value</code> option could be passed a format like <code>"%.1f"</code> to indicate to display 1 decimal point.</p>
<p>I think that would be a valuable contribution, I would certainly use it in my interact demos. </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20856#post-id-20856I agree. It was the case a while ago that we didn't display extra (zero) digits, then it wasn't, and I think finally it's what we have now. Someone asked about that in a talk I gave *today* about making interacts! File a bug and we have fodder for SD35.5 :)Sat, 19 Nov 2011 20:53:23 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20856#post-id-20856Comment by benjaminfjones for <p>As it is currently implemented, I don't believe <code>slider</code> has such an option to change the format of the displayed value. It would be a pretty easy project for a beginner to add this functionality to Sage. I could imagine changing the code in <code>interact.py</code> so that the <code>display_value</code> option could be passed a format like <code>"%.1f"</code> to indicate to display 1 decimal point.</p>
<p>I think that would be a valuable contribution, I would certainly use it in my interact demos. </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20854#post-id-20854This is now Trac #12060 and I will add it to the SD 35.5 wishlist.Sat, 19 Nov 2011 21:36:11 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=20854#post-id-20854Answer by Marcin Kostur for <p>Suppose you have a slider with given stepsize, say 0.1 like this</p>
<pre><code>@interact
def _(a=slider(1,100,0.1)):
print a
</code></pre>
<p>Is it possible to adjust this, such that the number printed to the right of the slider has only one decimal place? </p>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?answer=14568#post-id-14568 @interact
def _(x=slider( map(lambda x:x.n(digits=4),srange( 1,10,.1)) )):
print xThu, 21 Feb 2013 08:16:58 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?answer=14568#post-id-14568Comment by paulmasson for <pre><code>@interact
def _(x=slider( map(lambda x:x.n(digits=4),srange( 1,10,.1)) )):
print x
</code></pre>
https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=35994#post-id-35994Be aware when using this solution that `digits` sets the precision of the numerical value of `x`. Subsequent computations are limited by that precision and this can lead to unexpected round-off errors.Tue, 13 Dec 2016 03:00:28 +0100https://ask.sagemath.org/question/8496/decimal-places-in-slider/?comment=35994#post-id-35994