We use JavaScriptās standard number.toString in the inspector, which uses as few digits as possible to uniquely identify the value. Unfortunately that means thereās no way to control the number of displayed digits, short of rounding as you are already doing.
That said, you could implement the loop another way to avoid floating point error:
increment = {
while (true) {
for (var d = 0; d < 36000; d += 5) {
yield Promises.delay(25, d / 100);
}
}
}
You could also have a separate cell which represents the pretty, human-readable numberābut then youād see the value in two places.
DOM.text(increment.toFixed(2))
If you want to be super fancy, and have complete control over both the value thatās exposed programmatically to the rest of your notebook separately from how it appears in the page, you can use viewof
:
viewof increment = {
const pre = html`<pre class="O--inspect O--number">`;
pre.value = 0;
const interval = setInterval(() => {
pre.textContent = pre.value.toFixed(2);
pre.value += 0.05;
pre.dispatchEvent(new CustomEvent("input"));
}, 25);
yield pre;
try { yield Promises.never; }
finally { clearInterval(interval); }
}
In a sense, this makes the increment cell function like an input sliderāitās just that the user canāt control the slider; itās only controlled programmatically by the internal timer interval. So the increment value is displayed as a PRE element (for pretty formatting), but the value exposed to the rest of the notebook is a number, pre.value. And by dispatching an input event whenever that value changes, the rest of the notebook automatically reacts.
The last part, yielding Promises.never, is so you can dispose of the interval if the cell is ever re-evaluated: when Observable re-runs the cell, it calls generator.return so you can perform any necessary cleanup.
Thatās probably a little more detail that you were expecting but I wanted to convey that you have quite a few options to tackle this problem. 