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

286 Views Asked by At

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?

2

There are 2 best solutions below

0
On 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.

2
On

You could set a variable PointPressed to $0$. When "." is pressed set it to $1$. Set a variable PowerOfTen equal to $1$. In the number buttons, when pressed, update a in the same way, but also if PointPressed is $1$ set PowerOfTen = PowerOfTen*10. Instead of displaying a in the output, display a/PowerOfTen