Afrikaans
Akan
Albanian
Amharic
Armenian
Azerbaijani
Basque
Belarusian
Bemba
Bengali
Bihari
Bosnian
Breton
Bulgarian
Cambodian
Catalan
Cebuano
Cherokee
Chichewa
Chinese (Simplified)
Chinese (Traditional)
Corsican
Croatian
Czech
Danish
Dutch
English
Esperanto
Estonian
Ewe
Faroese
Filipino
Finnish
French
Frisian
Ga
Galician
Georgian
German
Greek
Guarani
Gujarati
Haitian Creole
Hausa
Hawaiian
Hebrew
Hindi
Hmong
Hungarian
Icelandic
Igbo
Indonesian
Interlingua
Irish
Italian
Japanese
Javanese
Kannada
Kazakh
Kinyarwanda
Kirundi
Kongo
Korean
Krio (Sierra Leone)
Kurdish
Kurdish (Soranรฎ)
Kyrgyz
Laothian
Latin
Latvian
Lingala
Lithuanian
Lozi
Luganda
Luo
Luxembourgish
Macedonian
Malagasy
Malay
Malayalam
Maltese
Maori
Marathi
Mauritian Creole
Moldavian
Mongolian
Myanmar (Burmese)
Montenegrin
Nepali
Nigerian Pidgin
Northern Sotho
Norwegian
Norwegian (Nynorsk)
Occitan
Oriya
Oromo
Pashto
Persian
Polish
Portuguese (Brazil)
Portuguese (Portugal)
Punjabi
Quechua
Romanian
Romansh
Runyakitara
Russian
Samoan
Scots Gaelic
Serbian
Serbo-Croatian
Sesotho
Setswana
Seychellois Creole
Shona
Sindhi
Sinhalese
Slovak
Slovenian
Somali
Spanish
Sundanese
Swahili
Swedish
Tajik
Tamil
Tatar
Telugu
Thai
Tigrinya
Tonga
Tshiluba
Tumbuka
Turkish
Turkmen
Twi
Uighur
Ukrainian
Urdu
Uzbek
Vietnamese
Welsh
Wolof
Xhosa
Yiddish
Yoruba
Zulu
Before we go too much further into the course let's quickly talk about rounding and how to avoid some
rounding errors.
We've got a combat scene here where damage is being taken damage is being dealt and you can see that
the values are being rounded.
However you may also notice the values aren't being rounded quite the way you might expect.
So we're probably already familiar with the traditional way that we round a number where say we have
a number two point seventy three for example.
And we want around that to one decimal place.
Well we look at the next number after our cutoff and we say that if that number is greater than or equal
to 5 then the number before it is increased by 1.
And if it's less than five then we just leave that number as is.
So two point seventy three would be rounded to two point seven.
Or if we were going to the nearest whole number then the seven is greater than five.
So the two point seven would round to three nice and simple.
One thing to watch out for is when the number that needs to change is a nine.
Let's take an extreme example of nine point nine nine and try rounding that to one decimal place.
Well this would cause this nine here to equal 10.
Now if we can't just put 10 in that column.
So we need to put in a zero and carry the one.
We then move over to the next number on the add that one we carried.
And that would give us 10 again.
And so in this example nine point nine nine would round to ten point zero.
It's important to note that whenever you need to give an answer to a certain level of precision in this
case one decimal place you need to keep those extra digits in there even if they are just zeros.
So in this case the answer is ten point zero not just 10.
It seems quite pedantic but it can become important in certain circumstances.
So it's worth remembering another option would be to take something called the floor of a number.
And what this essentially does is always rounds the number down to the nearest whole integer.
So regardless of what decimal places we have we essentially ignore them and round down there in our
example of two point seven three over here.
The floor would be to the opposite of this would be something called the ceiling of a number.
And what this does is always rounds the number up so again with our example of two point seven three
this would round up to three like it would normally.
But if we have another number say three point two this would round up to four and for the eagle eyed
among you you may know that that was what was actually happening in that combat clip at the start of
the video so why do we care about all of this.
Why don't we just round normally and be done with it.
Well let's say we have an enemy who is attacking our player.
This enemy is very weak compared to our player and only manages to inflict zero point six to points
of damage after some other modifiers have been added to it.
If we choose to round normally then this would do one point of damage but if it were any weaker then
it would probably do none at all or we could choose to be generous to our player and take the floor
of the number.
In essence we're saying the damage is always rounded in the player's favor.
And in this case it would do no damage at all.
Or we could do the opposite and be a little more harsh and always round the damage up by taking the
ceiling of the number an enemy would always be able to inflict some small amount of damage no matter
how weak it is in comparison to our player.
And this means that even the lowest level monster can kill our hero if they're on their absolute last
legs with all that said one thing to note at this point is that whenever you're doing a calculation
of any kind you should always perform the rounding last.
Otherwise you can start to introduce small errors and may compound over time.
For example let's take 5.1 times four point seven and then add 2.5 to that if we do that sum then it
gives us twenty six point four seven.
And if we round that then we get 26.
However if we round those numbers first say some function is returning a rounded version of the calculation
we get five times five plus three and that equals twenty eight.
And as you can see the end results are quite different.
So be very cautious when you're doing these sorts of thing to make sure these errors don't stack up
over time because this can lead to all sorts of weird and wonderful and unexpected behaviors in your
game with all of that out the way.
Let's look at how we might implement this in code.
Most modern languages have some sort of math library that you can access and the syntax is fairly similar
between each one.
So for rounding we can use math dot round.
And then in the parentheses you'd include the number you want to round and the level of precision that
you're looking for.
So this would be say 1 for one decimal place or five for five decimal places etc. the floor and the
ceiling are very similar to this except we don't need to specify any level of precision since we're
always just rounding to the nearest whole number so we have math dot floor passing in our number and
we have math dot seal passing in our number.
Notice though that the method for sealing has been abbreviated to seal here CEI L and that's usually
the case across the board.
So it's worth keeping in mind.
Okay.
So hopefully that clears up how rounding works and how to avoid some of the common pitfalls you might
come across.
We haven't covered rounding with significant figures yet but we'll cover that when we get on to scientific
notation finally.
It's time for your challenge.
So I'd like you to take the number six point two eight three and I'd like you to find the flaw of this
number.
I'd also like you'd find the ceiling of the number and I'd like you to find the number two 1 and 2 decimal
places.
So once you've got your answer pop it in the community forum and I'll see you in the next lecture.
Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.