In this section, we are going to be looking at JavaScript, no methods, particularly parse integer,
add to fixed.
So these are commonly used in JavaScript.
And in order to convert and make sure that your variable is a number so you can use number or parse
integer, that will turn that value into a number as well as two fixed is commonly used.
Whenever you're doing calculations with that, you expect at least two decimal places.
Then you can set it to two fixed too, and that will provide two decimal places.
So in line with currencies and there's more information that's available at the Mozilla Developer Network.
So I've got the link within the reference guide and you can see that we're setting up.
So there's option to set up a new number.
You can declare it as a new number and you can also update and convert a string value into a number.
So turning B is equal to 123 is true, whereas this value is going to be false because we're setting
this up.
But it's not actually a number that we're passing in there.
So a is an instance of a number.
B is an instance of a number.
So A is an instance of a number because we're setting it up as a amber object.
But it's going to be returned back as false because we're not passing the number in there.
And for most of the time, the way that you're going to be using it is you're going to be converting
strings to numbers in JavaScript.
And there's a bunch of other options here for numbers.
And these aren't as commonly used.
The one that is important to note is, is not to determine whether a value passed in is a number.
So you get a boolean returned there depending on if it's a number or not.
There's an example here of a value being passed in and we see that this is not a number.
So we get return back, not a number, and you can run this and see the results.
So the challenge for this lesson is to try some of the number methods and I'll show you and I'll walk
you through some of those.
Let's create some numbers.
So we've got my number one and setting this up to let's give it a value with the bunch of decimal places
and we'll try the two fixed as well as we've got another one.
So my number two and we can take this value and this will be a string.
We're going to convert that one to a number and then using the console will use console log to log out
that number value.
So for now, we'll just log out my number one and assume it gets logged out as well as by number two.
It will do some conversions.
So when we refresh, we see that the first one is a number because it's blue in the console and then
the second one is black because that's not a number.
So if we did want to turn it into a number, there's a number of ways to do this.
So if we wanted to turn my NUM into a number, we could use a number and then wrap it within the rounded
brackets and pass in a value.
So this is where we could pass on any value that we wanted.
We could pass in a string value.
You can see that that turns it into a number.
If you pass in a boolean value, you can see that also turns it into a number.
So this is another way to use number where you can convert any type of that variable value into a number
if it converts into a number.
And if you try to convert something that's not a no test, then you get return back any.
And so that's the result that you can get back if it can't be converted into a number of format.
And of course, my number one is already a number, so there's nothing to convert there.
You can also do it pass integer.
So this is another way to convert a value into a number.
You can see it does convert it into a no output boolean value and that not a number, whereas number
was converting those booleans into numbers.
When we have a boolean in percentage or it's only going to pass it into an integer, it's not going
to try to convert it into a number.
So that's the difference there.
Slight difference in the way that you can use these.
The other one that we can use as well is we can use the two fixed, which allows us to take a value.
So this one, we do have a number.
So using my number one, we're going to apply the two fixed to it.
And then this is where we can set the number of decimal places we want to go.
So in this case, we've got four.
And most commonly when you are using currencies, of course, you've got dollars and cents.
So converting it into DOT 32 is ideal when you're outputting a value in a currency form.
So go ahead and try all of these out, have some fun with that experiment with it and get more familiar
with what you can do with no methods in JavaScript.