1
00:00:00,240 --> 00:00:06,180
In this section, we are going to be looking at JavaScript, no methods, particularly parse integer,

2
00:00:06,180 --> 00:00:07,230
add to fixed.

3
00:00:07,350 --> 00:00:09,630
So these are commonly used in JavaScript.

4
00:00:09,750 --> 00:00:15,600
And in order to convert and make sure that your variable is a number so you can use number or parse

5
00:00:15,600 --> 00:00:21,060
integer, that will turn that value into a number as well as two fixed is commonly used.

6
00:00:21,060 --> 00:00:26,010
Whenever you're doing calculations with that, you expect at least two decimal places.

7
00:00:26,190 --> 00:00:30,240
Then you can set it to two fixed too, and that will provide two decimal places.

8
00:00:30,450 --> 00:00:36,360
So in line with currencies and there's more information that's available at the Mozilla Developer Network.

9
00:00:36,570 --> 00:00:40,860
So I've got the link within the reference guide and you can see that we're setting up.

10
00:00:40,860 --> 00:00:42,750
So there's option to set up a new number.

11
00:00:42,750 --> 00:00:48,940
You can declare it as a new number and you can also update and convert a string value into a number.

12
00:00:48,960 --> 00:00:57,000
So turning B is equal to 123 is true, whereas this value is going to be false because we're setting

13
00:00:57,000 --> 00:00:57,390
this up.

14
00:00:57,390 --> 00:00:59,930
But it's not actually a number that we're passing in there.

15
00:01:00,270 --> 00:01:01,980
So a is an instance of a number.

16
00:01:02,100 --> 00:01:04,200
B is an instance of a number.

17
00:01:04,320 --> 00:01:08,880
So A is an instance of a number because we're setting it up as a amber object.

18
00:01:08,970 --> 00:01:12,470
But it's going to be returned back as false because we're not passing the number in there.

19
00:01:12,540 --> 00:01:16,590
And for most of the time, the way that you're going to be using it is you're going to be converting

20
00:01:16,590 --> 00:01:18,990
strings to numbers in JavaScript.

21
00:01:19,140 --> 00:01:21,960
And there's a bunch of other options here for numbers.

22
00:01:22,200 --> 00:01:24,750
And these aren't as commonly used.

23
00:01:24,960 --> 00:01:30,990
The one that is important to note is, is not to determine whether a value passed in is a number.

24
00:01:31,140 --> 00:01:35,220
So you get a boolean returned there depending on if it's a number or not.

25
00:01:35,400 --> 00:01:40,860
There's an example here of a value being passed in and we see that this is not a number.

26
00:01:40,860 --> 00:01:45,020
So we get return back, not a number, and you can run this and see the results.

27
00:01:45,210 --> 00:01:49,890
So the challenge for this lesson is to try some of the number methods and I'll show you and I'll walk

28
00:01:49,890 --> 00:01:50,990
you through some of those.

29
00:01:51,000 --> 00:01:52,660
Let's create some numbers.

30
00:01:52,660 --> 00:01:59,460
So we've got my number one and setting this up to let's give it a value with the bunch of decimal places

31
00:01:59,460 --> 00:02:02,920
and we'll try the two fixed as well as we've got another one.

32
00:02:02,990 --> 00:02:07,320
So my number two and we can take this value and this will be a string.

33
00:02:07,660 --> 00:02:15,840
We're going to convert that one to a number and then using the console will use console log to log out

34
00:02:15,840 --> 00:02:16,880
that number value.

35
00:02:17,430 --> 00:02:23,640
So for now, we'll just log out my number one and assume it gets logged out as well as by number two.

36
00:02:23,760 --> 00:02:25,160
It will do some conversions.

37
00:02:25,170 --> 00:02:30,900
So when we refresh, we see that the first one is a number because it's blue in the console and then

38
00:02:30,900 --> 00:02:33,500
the second one is black because that's not a number.

39
00:02:33,660 --> 00:02:37,140
So if we did want to turn it into a number, there's a number of ways to do this.

40
00:02:37,620 --> 00:02:44,220
So if we wanted to turn my NUM into a number, we could use a number and then wrap it within the rounded

41
00:02:44,220 --> 00:02:46,270
brackets and pass in a value.

42
00:02:46,440 --> 00:02:49,470
So this is where we could pass on any value that we wanted.

43
00:02:49,620 --> 00:02:51,130
We could pass in a string value.

44
00:02:51,150 --> 00:02:52,860
You can see that that turns it into a number.

45
00:02:53,160 --> 00:02:57,730
If you pass in a boolean value, you can see that also turns it into a number.

46
00:02:57,930 --> 00:03:04,640
So this is another way to use number where you can convert any type of that variable value into a number

47
00:03:04,650 --> 00:03:05,910
if it converts into a number.

48
00:03:05,910 --> 00:03:10,970
And if you try to convert something that's not a no test, then you get return back any.

49
00:03:10,980 --> 00:03:16,200
And so that's the result that you can get back if it can't be converted into a number of format.

50
00:03:16,530 --> 00:03:22,200
And of course, my number one is already a number, so there's nothing to convert there.

51
00:03:22,440 --> 00:03:24,770
You can also do it pass integer.

52
00:03:25,020 --> 00:03:28,170
So this is another way to convert a value into a number.

53
00:03:29,060 --> 00:03:36,090
You can see it does convert it into a no output boolean value and that not a number, whereas number

54
00:03:36,180 --> 00:03:39,300
was converting those booleans into numbers.

55
00:03:39,570 --> 00:03:45,030
When we have a boolean in percentage or it's only going to pass it into an integer, it's not going

56
00:03:45,030 --> 00:03:46,440
to try to convert it into a number.

57
00:03:46,440 --> 00:03:47,850
So that's the difference there.

58
00:03:48,000 --> 00:03:50,460
Slight difference in the way that you can use these.

59
00:03:51,060 --> 00:03:58,290
The other one that we can use as well is we can use the two fixed, which allows us to take a value.

60
00:03:58,330 --> 00:04:00,020
So this one, we do have a number.

61
00:04:00,540 --> 00:04:05,280
So using my number one, we're going to apply the two fixed to it.

62
00:04:05,490 --> 00:04:08,940
And then this is where we can set the number of decimal places we want to go.

63
00:04:09,120 --> 00:04:10,680
So in this case, we've got four.

64
00:04:10,800 --> 00:04:15,260
And most commonly when you are using currencies, of course, you've got dollars and cents.

65
00:04:15,510 --> 00:04:23,520
So converting it into DOT 32 is ideal when you're outputting a value in a currency form.

66
00:04:23,790 --> 00:04:29,700
So go ahead and try all of these out, have some fun with that experiment with it and get more familiar

67
00:04:29,700 --> 00:04:31,950
with what you can do with no methods in JavaScript.
