How can you make a decimal point for a number display on Desmos

desmos

I have this Desmos graph which is a number display. You type a button and that number gets displayed. I'm thinking about turning it into a calculator, but first I need a decimal point. (Also the negative function doesn't work, but that's a problem for another time). The way the display works is that I have a slider $a$ for the number being typed. Every subsequent digit $n$ you type, it preforms the action $a\rightarrow10a+n$.

I've tried having a separate slider "$p$" with a step of 1 to represent the place of the decimal point, but I have yet to figure out how to utilise it. The closest thing I've seen for what I'm trying to find is on this graph from a contest in $2020$, but I have absolutely no clue what the heck is going on in there.

I think it should be something along the lines of this: "after the decimal point is placed, every subsequent digit $q$ typed will be divided by [the place of the decimal point times ten] and then added onto the total", but I'm still not entirely sure how I would go about doing that.

Any ideas?

Best Answer

You can keep track on how many decimal places there are, like in this Desmos plot based on yours. What it does:

  • It introduces a new var d that keeps track on whether . was pressed (0 or 1).

  • When C is pressed, thend → 0, p → 0, and s → 1.

  • There is a new var b that is $b=s\cdot a\cdot 10^{-p}$, and the big black field now displays b (formerly a).

  • On pressing a digit, p is incremented by d.

Now when you type, say, 0.12 then b = 0.12 will hold that value, and it is displayed as such in the big black rectangle.


What I don't know how to do is when you press 0.0 which should display 0.0, but it will only start to display something other than 0 when you type a non-zero digit. To fix this, one would need strings.

Related Question