All language subtitles for 014 Type-casting_en

af Afrikaans
ak Akan
sq Albanian
am Amharic
ar Arabic
hy Armenian
az Azerbaijani
eu Basque
be Belarusian
bem Bemba
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
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
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

In Java, we can cast a variable from one type to another.

So far, you learn to create variables that store five types of values int.

Long double.

Car and street.

In this lesson, we're going to use typecasting to convert a value from one type to another.

The first thing I'll need you to do is create a new class by yourself, so inside the section to project

create a new file name type conversion Java and make sure the type conversion class has a main method.

OK, the first thing we'll address is how we can cast a value from double to.

In other words, you can convert a double value to an integer.

Imagine we have a double variable called decimal and it stores the value four point three.

We also have an invariable integer, and right now it equals nothing, so we want to copy the first

value into integer, but remember that into variables cannot store decimals.

They can only store whole numbers.

So before you can store this value into an integer variable, you need to cast a double value to it.

And we can do that by specifying two things, telling Java the type that we're casting to.

In this case, we want to cast some value to end and then specify the value that you want to copy in

this case, it's the decimal.

So what job is going to do is convert the double Valetta into by cutting off the decimal, resulting

in a whole number, and now the invalid integer stores the previous value as a whole?

No.

I thought of a fun example where your friend Percy, let's call him, needs help calculating his salary.

So what we're going to do is make a double variable, double salary.

And let's assume you calculated the salary to be five thousand eight hundred and thirty three dollars

point thirty three cents.

And for the sake of it, let's add a bunch of more threes because we will assume the calculator spat

out that number.

OK, we need to print this family so that person can see it, system dot, dot, print nine.

And will say Pearse's.

Salary is.

In dollars.

Whatever the salary value is.

Go ahead and compile a code.

All right, now, looking at this message, accuracy is a really important in the thousands of dollars,

do we really care about cents, much less the other decimal points?

In this case, it would make more sense to express the salary as a whole number and not care about what

the calculator gave us.

So let's make another variable of type it into a rounded salary.

And we're going to cast the first Valetta at.

Int salary.

And what that's going to return is a whole no version of the salary value.

All right, recompiling our code.

And printing it and this looks a lot cleaner.

In the real world, data comes in many forms, and your job is to present this data to the user in a

clean and practical way.

In this case, the salary value came in as a double.

It had many useless decimal points.

So you cast the double value as an integer.

And printing this family looks much better.

In this lesson, you learn to cast values from one type to another, the salary value came in as a double.

It had many useless decimal point.

So you cast the double value at printing this value.

Look more presentable and converting between types is very common.

So for now, I encourage you to test your knowledge by doing the quiz and trying out the next workbook.

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