Welcome back.
And this video, we're going to add a decimal point because, well, we could of course have this calculator,
which can only work with whole numbers, but how about having a decimal point here at the bottom left,
which then allows us to use some proper float calculations as well?
So what I'm going to do is I'm going to use this button as zero here and I'm going to add just another
one before that.
So this one will be button dot.
OK, and then we can go ahead and give it eight different text.
I'm just going to use the pin point here or DOT, and let's add a string.
Like so, OK, so now accordingly, they all both have to have a weight of one now.
Otherwise, it would look a little awkward.
So here we have the zero.
We have the thought now.
We could, of course, change the order.
If you want to, but I think that's fine as we have them now.
Now, accordingly, we will need to have a specific method that will take care of what should happen
once we click on a decimal point and I'm going to create a method here called on decimal.
Point.
So once we click on it, we will get a view as the parameters here and not once we click on it, I want
to execute something.
Now the important part is that this should only work if the last entry that we had was not a dot because
if we already had a dot, I don't want to use another dot.
OK, so that's really important here.
And in order to find that out, I will require a another variable or actually two variables here.
So one of them will be whether the last one was numeric and the other one will be whether the last one
was a dot.
So here are a last numeric, which will be of type Boolean, and I'm going to set that to false.
And then the other one will be last dot, which would be of type Boolean as well.
And we could, of course, just leave this column Boolean out here.
It would work all the same, but that's basically how I want to start this thing because if it was a
number that was pressed, I want to treat this dot differently than it.
If there was a thought that was pressed because if there was a dot, I don't want to be able to create
another dot.
Otherwise, we would have three dot dot zero, for example.
So that's what we want to avoid.
And in order to avoid that, what we can do is we can use an if statement here that will help us with
that.
So here we can check if.
The last numeric is true, and it's not a dot.
So not last dot.
So you see if last name is true.
And at the same time, it's not last dot.
Then I want to execute some code and that this is exclamation mark here, which make sure that this
is not lost.
So if last thought is not true, which means it's false, only then this code will be executed here
in those curly brackets.
So what do we want to do here?
Well, then I just want to append my dot.
That's it.
That's as simple as that.
And at the same time, if that happened, I need to make sure that the last numeric is going to be false
because otherwise it would never change, right?
The same goes for lost dot.
That needs to be true now, because now the last entry that we had into our TV input was, in fact,
a dot.
So what we're using here are flags.
OK, so this is just a flag last numeric and last thought, there are flags which help us to know if
something is currently active or inactive, so to speak.
OK, so now at this point, let's go ahead and use this on decimal points, I'm going to copy it from
here.
I'm going to go over and assign that to my button dot ID here.
So to this button, and once it is pressed, I will use the on decimal point here and will execute it.
And now that we have assigned the tier, and if we were to test it, we would notice that it still doesn't
work.
Why would that happen?
So let's see, this button just doesn't do anything.
Is it something wrong with this method?
Well, actually, no.
The method itself is fine.
You see, it's connected and it's running, and all is good.
But the problem is that last numeric is never set to true.
And we are setting it to false here.
And this means that this if statement is always going to be false.
So this quote will never be executed.
So we need to make sure that once we press on a digit that our last numeric will be set to true.
And at the same time, our last thought will also be set to false because now it's not a product anymore
that we had entered last, but it was a no.
So let's run it again.
So zero zero.
And you see, now I can still go on and on and on to add zeros, I could add a piece here, but that
is not the point for now, so that's fine for now.
We're going to fix that later on.
But at least we do have the capability of adding dots, but not multiple dots after another.
So that's it for this video.
See you in the next one.