Hello and welcome back to Section four, lesson for no manipulation.
So what we're going to talk about here as a follow up to the previous lesson, which was on just numbers
and how those are formatted, we're going to talk about a number of different methods.
You can chain on to the number library in order to verify numbers limits.
OK, so let's take a look at this in code.
First things first.
We saw that we could take a string, so let's take a string like George.
OK, now, if we try to turn this into a no, let's just see what happens.
OK, it returns as not a number, but it has been modified by the no class, so let's try something
else.
Let's try let's try to turn five sixty seven.
Into a number, we can see that that turns into a number just fine.
And now we're going to try is a number is not yet.
So what this checks is if this thing has been turned into a number, is it not a number?
OK, so basically we're just checking to see if this is not a number of returns.
A boolean value indicates whether the value is a is the reserved value, not a number.
Unlike the global, this won't forcefully convert it to a no, so there's a difference here, basically,
I'll show you the difference.
So that checks and says this is false.
OK, it's it's not a number, not a number, but if we did go here and get rid of this number class,
just use the default is not a number and see that you could see that returns as true.
OK.
Now, if we were to do that here, this would also return as falls for this second value because it
is a No.
And if we wanted to return true, then we could do something like.
We could do something like let's bring equal George and then we could no that street first.
And then we could check
whether that is not a number there.
So now this second value here.
It's going to verify that this is not a number, so it has been modified by the no class and it's still
a string, George, so it's not a no.
OK, it's converted it forcefully converted it to a number type, but it can't pass this as a number
of value.
So it is the reserve value, not a number at this point.
OK.
If we were just to consider log what that is, you could see it
not a number.
OK, so if it returns with this value, not a number, then number is any end will return as true.
OK, so let's look at a number of other methods.
Now we're going to do is finite, OK?
So let's start with
let's start with council log, but we're going to do is finite now finite means it just has an end.
Does a number not like Pi?
Pi doesn't have an end.
It's it's this irrational number that goes on forever.
This also let's just see what happens now.
Ten divided by three is interesting because three is not a factor of 10.
If you divide ten by three, you get three point three three three three three repeating.
So let's see what it says.
That returns as a finite value.
So unlike the global is fine, it also it doesn't forcibly convert the parameter to a number, but because
it understands that this actually is a rounded number because of how numbers work in JavaScript, if
you print this out, it's going to round it.
So it's not going to misunderstand that and it's going to treat it as a finite number.
So just to see you're aware of that now, we can check if this is an integer and it should fail this
one, an integer means it has no decimal values, so it has no period after the number and no trailing
digits after a period.
So if we tried this one, we get false, understandably, because ten divided by three is a decimal
number.
So it would be like it'd be the same as me just doing three three three three three three three three
five.
Or to be more specific, if you were to round it with proper rounding, you would be just that.
OK, this is not an integer, this is a decimal value.
And so it shows up as such.
And you can also develop what is called a.
Safe integer value and check is safe integer, and that's going to check for any value less than negative
this number and greater than positive of that number.
So what that's going to do?
The reason for that is the number primitive class right here for primitive numbers in JavaScript just
doesn't support double precision or rounding to numbers outside of this range right here.
So you could check this number and see, hey, is this safe?
It is good if you go on higher.
It isn't OK.
So any number in that range, and this corresponds with the value to to the fifty third power, minus
one.
So two to the fifty third power is not a safe integer because it is higher than that double precision.
Number two to the fifty third power.
OK, in bits that would be one higher than or one digit more in binary than the value represented by
two to the fifty third.
OK, so that will show you what is a safe integer.
If you want to use numbers bigger than this, which you might want to do at some point, which is about
nine quadrillion.
So if you wanted to show this with commas, you could do this.
Obviously, this won't be understood by the by the code, but that's what the number would look like
with commas.
OK, if you want to use numbers bigger than that, then there is a class you can use called Big Int.
And that's that's something that will allow you to use numbers bigger than nine quadrillion.
OK, a couple of other things you can do.
You can do pass, float.
And pass it.
So if we pass it with
we can say ninety nine balloons and we'll do the same thing here.
So if you try with that, it's going to grab whatever numbers are at the beginning of that string and
convert that string into a number.
So it's just going to use whatever it can find, it's going to pass it, which means it's going to read
through it and find the float, which is one type of a number.
It's going to read through it and find the integer and then stop.
OK, so this is very similar.
This is basically the same as you can use this without the no class.
You can just use it globally like this and do the same thing.
And it's just going to grab the numbers from the beginning of the string and then go from there.
But the difference here is that between these two is that past float will grab decimal values, OK,
but pass it, as you can see, will not grab decimal values.
So you get ninety nine point four or five out of ninety nine point four or five balloons and ninety
nine out of ninety nine point four or five balloons with it.
Because this is an integer integer, as I said, is a rounded number with no decimal values.
A float is can be a decimal value with multiple decimals.
OK, and that's it for number method's.
There are a number of other ones you can take a look at, so check the resources we'll see in the next
lesson.