Bummer! This is just a preview. You need to be signed in with a Basic account to view the entire video.
Start a free Basic trial
to watch this video
While integers hold whole numbers, floats hold fractions. Let's find out how to use floats in PHP.

0:00
Next up, lets talk a little bit about floats.

0:02
So floats or floating point integers or real numbers or doubles, whatever

0:08
you want to call them, we call them floats inside of PHP or floating point numbers.

0:14
So, we need that when we're doing things that have a decimal place.

0:18
Lets say we want to find out a distance of a trip.

0:22
So we'll say we have two variables here, distance to

0:27
home and we'll set that equal to a floating point number.

0:33
The way we do that is simply say 1 and then whatever, so

0:37
1.2, close it with a semicolon for our statement.

0:41
Then we'll add another variable that's a floating point.

0:43
So distance to work.

0:48
Same thing.

0:49
Maybe we'll do 2.5.

0:52
Now we can use the same type of operations we have done before.

0:56
We'll actually do that down below.

0:59
We'll do it here.

1:00
We'll create another list item and

1:03
then inside of this one we'll do a bit of math here.

1:07
So let's say we want to echo the distance

1:13
to work plus our distance to home.

1:23
Alright, we'll save that, switch back over and refresh.

1:27
And you see we can take floating point numbers and

1:29
sum them together and get returned a floating point.

1:33
Now, what if we were to add a nonfloating point number to this equation?

1:37
So let's say, we'll add the integer variable 3, which is a whole number.

1:44
Save that, switch over and refresh, 6.7.

1:49
So if we take whole numbers and we sum them to floating point numbers,

1:54
we're still going to get a floating point in return.
You need to sign up for Treehouse in order to download course files.
Sign up