All language subtitles for 13. Removing Decimal Part from an Integer - Solution

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
bn Bengali
bh Bihari
bs Bosnian
br Breton
bg Bulgarian
km Cambodian
ca Catalan
ceb Cebuano
chr Cherokee
ny Chichewa
zh-CN Chinese (Simplified)
zh-TW Chinese (Traditional)
co Corsican
hr Croatian
cs Czech
da Danish
nl Dutch
en English
eo Esperanto
et Estonian
ee Ewe
fo Faroese
tl Filipino
fi Finnish
fr French
fy Frisian
gaa Ga
gl Galician
ka Georgian
de German
el Greek
gn Guarani
gu Gujarati
ht Haitian Creole
ha Hausa
haw Hawaiian
iw Hebrew
hi Hindi
hmn Hmong
hu Hungarian Download
is Icelandic
ig Igbo
id Indonesian
ia Interlingua
ga Irish
it Italian
ja Japanese
jw Javanese
kn Kannada
kk Kazakh
rw Kinyarwanda
rn Kirundi
kg Kongo
ko Korean
kri Krio (Sierra Leone)
ku Kurdish
ckb Kurdish (Soranî)
ky Kyrgyz
lo Laothian
la Latin
lv Latvian
ln Lingala
lt Lithuanian
loz Lozi
lg Luganda
ach Luo
lb Luxembourgish
mk Macedonian
mg Malagasy
ms Malay
ml Malayalam
mt Maltese
mi Maori
mr Marathi
mfe Mauritian Creole
mo Moldavian
mn Mongolian
my Myanmar (Burmese)
sr-ME Montenegrin
ne Nepali
pcm Nigerian Pidgin
nso Northern Sotho
no Norwegian
nn Norwegian (Nynorsk)
oc Occitan
or Oriya
om Oromo
ps Pashto
fa Persian
pl Polish
pt-BR Portuguese (Brazil)
pt Portuguese (Portugal)
pa Punjabi
qu Quechua
ro Romanian
rm Romansh
nyn Runyakitara
ru Russian
sm Samoan
gd Scots Gaelic
sr Serbian
sh Serbo-Croatian
st Sesotho
tn Setswana
crs Seychellois Creole
sn Shona
sd Sindhi
si Sinhalese
sk Slovak
sl Slovenian
so Somali
es Spanish
es-419 Spanish (Latin American)
su Sundanese
sw Swahili
sv Swedish
tg Tajik
ta Tamil
tt Tatar
te Telugu
th Thai
ti Tigrinya
to Tonga
lua Tshiluba
tum Tumbuka
tr Turkish
tk Turkmen
tw Twi
ug Uighur
uk Ukrainian
ur Urdu
uz Uzbek
vi Vietnamese
cy Welsh
wo Wolof
xh Xhosa
yi Yiddish
yo Yoruba
zu Zulu

Original subtitles

So now that you tried to solve this exercise on your own, let's give it a shot together, shall we?

And first of all, we have to understand is let's just use the example, the previous example that we

have some data variable needs of a floating point, floating point type.

Right.

And for example, we had like twelve point seven with what we are requested to do is to extract these

information, these zero point seven after the decimal point.

So first of all, what I want us to do is just a quick reminder of how would you extract just the integer

type, right.

Just these 12 without a point seven.

And based on the result and based on the way that we are going to do it and the way that we've done

it previously, we are going to extract also these points zero.

So I hope you're ready to get yourself something nice to drink or maybe a pen and to write some notes.

And here we go.

So the first thing that we have to do is to create to declare a variable float data, write right after

words.

We are going to read these data, these value from the user.

So print f, print F, enter the data of floating point tied, for example.

OK, here we are going to read these data from the user by using this kind of function and we are going

to use the percentage F and to write it into data.

That's how we are going to solve it.

OK, so that's the first step.

Now what we have to do is if we want to print the integer itself, for example, the twelve, the full

part of these decimal number, what we have to do is simply just print half the decimal or the integer.

The integer better.

The integer path equals to percentage deep.

OK, instead at least percentage we if we would have used data.

OK, then let's see what will happen.

So build and run it.

Let's say we have twelve point seven and you will see some really strange number.

Right, one six one oh six.

Well what is that.

I'm trying just to get the percentage of data.

So there is a problem here.

Why didn't we get just 12?

And the reason is very simple, because data is stored as a float.

Right, as a floating memory.

And we are trying to read this information is an integer.

So here we have a problem.

OK, I'm not going to dive into all the details, into all the bytes and bits, let's say, of this

variable and how it's being read.

But simply know that if you store it as a float and you're trying to read it without any explicit casting

as an integer, then unexpected behavior may occur.

So what you have to do is, for example, to use explicit casting and to specify here and OK, so that's

an explicit casting.

And if we are going to build and run it, you will see that you get the integer parts 12, because you

know that INT is an explicit casting if you use it this way and it will simply take the integer part

of a given floating point number like we have here with data.

So I hope that's clear, right.

No questions about it.

If you still have any questions, feel free to ask them.

And all that remains right now is to pretend not the integer part, but rather the decimal part after

the decimal point.

So how it can be done?

It's actually it's very simple because you know that the initial data is twelve point seven, for example,

and we know how to get the integer part of the full part of it.

So if we will take the initial the actual data and subtracted with it, well, OK.

So if we use something like this so we know how to get the twelve and we are going to use twelve point

seven minus twelve and it will give us.

What do you think it will give us.

Zero point seven, which is exactly the floating point, the decimal path that we wanted to get.

So how should we do it?

So Preens have proven to have the decimal part, that same old part after the floating point.

After the floating point equal is two percentage F and here instead of the percent.

Jeff Placeholder, we are going to take the data, right, that's the initial data and use subtraction

of input data.

So we simply took twelve point seven minus 12.

Right, because we take just the integer path.

And basically what we got is the decimal part out of a hold of a given floating point variable, out

of a given floating point value.

So let's let's build and run it and see what happens.

So enter the data floating point type, let's say twelve point seven.

And there you go.

The decimal part is this one.

The integer part is that one freaking awesome.

And what now we have to do let's do another example.

We don't have to do anything right now.

Basically.

No, there was one thing that wanted to do is simply to kind of limit to the number of zeroes that we

can see.

Two point one, for example.

Okay.

Or point to let's make it like this.

So let's say five point seventy five.

So we expect the integer part to be five and the decimal bar to be zero point seventy five five and

zero point seventy five.

Awesome.

Guys, I think that's amazing.

Good job.

I guess that by now you start feeling like you're more confident with your knowledge and with applying

your skills in our C programming language.

So keep on practicing, keep on working hard.

And trust me, guys, there is no reason why if you have a lot of free time, I hope you do.

If not, try to find always some balance, try to find some free time to exercise and to solve more

exercises.

You're not wasting time for those of you who say, oh, that's very easy.

I know this one.

I know how to solve this one.

No, it's it's not the case.

It's the more you practice, the better you will be.

The more you learn, the smarter you probably will be.

So take your time, put in the hustle the hard work, and I guess you are about to succeed.

So my name is Vlad.

This is Alphatech.

Thank you so much for watching and I will see you next time.

Can't find what you're looking for?
Get subtitles in any language from opensubtitles.com, and translate them here.