WEBVTT

00:00.080 --> 00:00.380
Okay.

00:00.380 --> 00:02.960
So let's talk about the numbers in PHP.

00:02.960 --> 00:05.990
So we've already covered that plenty of times.

00:05.990 --> 00:07.460
But let's have a reminder.

00:07.460 --> 00:09.050
So we have integers.

00:09.050 --> 00:15.200
And we've got floating point numbers like this p number right here.

00:15.380 --> 00:25.490
Now you can cast strings to integers by using the int operator like that.

00:25.490 --> 00:30.740
And also you can cast floating point numbers to integers.

00:34.520 --> 00:36.170
Like this.

00:37.970 --> 00:41.690
Now let's all vardump this to see what are the values.

00:41.690 --> 00:43.430
So integer and float.

00:43.550 --> 00:49.010
This should be obvious and string to integer and float to integer.

00:49.040 --> 00:50.690
Let's see what's the effect.

00:50.690 --> 00:53.750
Let's run numbers.

00:53.990 --> 00:54.350
PHP.

00:54.440 --> 00:55.490
There it is.

00:56.420 --> 01:00.080
So next up there are some arithmetic Relations.

01:00.080 --> 01:06.050
So I don't think there is much point in showing them because they are pretty basic.

01:06.170 --> 01:16.160
Like you've got addition, subtraction, you can multiply or divide values, but an interesting one

01:16.160 --> 01:21.470
is modulus, which is the remainder of a division by a number.

01:21.470 --> 01:25.940
And this is often used to find odd and even numbers.

01:26.120 --> 01:32.210
Let's say you've got seven and you just do modulo by two.

01:32.450 --> 01:40.580
And if the remainder is one, this means it is an odd number, and if the remainder is zero, this means

01:40.580 --> 01:42.590
it is an even number.

01:46.040 --> 01:46.460
Okay.

01:46.460 --> 01:54.050
And something that's really interesting and useful with numbers is all the mathematical operations.

01:54.170 --> 01:57.620
So for example rounding of the numbers.

01:57.620 --> 02:05.240
So I promised you that before, and we haven't really done that other than actually casting a float

02:05.270 --> 02:11.780
number to an integer, which in this case 399 always casts to three.

02:11.810 --> 02:18.410
That might not be what you really want, especially if you, let's say, want to be fair.

02:18.410 --> 02:28.910
And let's assume this is an average rating of a book or movie, or someone grades 399 is really close

02:28.910 --> 02:34.730
to four, so it should be rounded up to four, not rounded down to three.

02:34.730 --> 02:39.410
And there are different functions that just do it differently.

02:39.440 --> 02:44.180
So first round with three seven.

02:44.300 --> 02:48.800
And then let's do round with 3.4.

02:49.820 --> 02:51.200
Let's run this.

02:51.440 --> 02:55.790
So as you see the 3.7 rounds to four.

02:55.790 --> 03:01.160
But if it is Below three and a half, it rounds to three.

03:01.460 --> 03:03.530
So this is how round works.

03:03.530 --> 03:07.820
But there also is a floor function.

03:07.850 --> 03:10.790
Let's run it for 3.8.

03:10.820 --> 03:14.570
And it will also always round down.

03:14.900 --> 03:17.720
Then there is a scale function.

03:19.280 --> 03:21.410
Let's run it on 3.1.

03:21.440 --> 03:24.620
This would always round up.

03:26.990 --> 03:31.460
Next up there are some functions like minimum or maximum.

03:32.030 --> 03:42.290
So it basically will find either the minimum or the maximum functions from those given.

03:42.320 --> 03:47.960
This is often very useful especially for algorithms as you see.

03:47.990 --> 03:49.100
Minimum is one.

03:49.130 --> 03:52.880
Maximum is seven which makes perfect sense.

03:53.210 --> 03:58.550
Then randomizing and generating a random number.

03:58.550 --> 04:06.050
So this would give you a random number every single time we've got two, then we've got five, etc.

04:06.050 --> 04:10.700
and an absolute function abs.

04:10.730 --> 04:13.730
And this just gives you an absolute value of a number.

04:13.730 --> 04:17.210
So in case of minus five this would be five.

04:17.930 --> 04:21.350
Then there is the number formatting.

04:21.350 --> 04:31.190
So let's come up with a number maybe something like this.

04:34.910 --> 04:40.790
And then you might want to format it in a specific way.

04:40.790 --> 04:48.500
So there is the number format function to which you can pass the number.

04:50.330 --> 04:53.420
Then you can choose how many decimals you would like.

04:53.420 --> 04:55.400
So it defaults to zero.

04:55.730 --> 04:59.660
So maybe if this has more I can just select that.

04:59.660 --> 05:01.850
I'd like two decimals.

05:01.850 --> 05:11.540
And this really makes sense for the currencies and all the numbers that needs to have at most two decimals,

05:11.540 --> 05:17.120
because more decimals would make zero sense for such numbers.

05:17.240 --> 05:20.690
And then you have decimal separator.

05:20.690 --> 05:24.560
By default it's dot but it differs across countries.

05:24.560 --> 05:27.920
So you might use a comma.

05:28.340 --> 05:32.330
And then the final one is thousands separator.

05:32.330 --> 05:37.100
So there are countries which don't use any thousands separator.

05:37.100 --> 05:39.230
And there are countries which do.

05:40.550 --> 05:44.600
So maybe let's use a dot for the floating point number separation.

05:44.600 --> 05:45.740
And.

05:48.140 --> 05:53.960
This is how this number right here was formatted.
