Types are how we identify different kinds of data from the real world. Kotlin has many different basic types, including integers, floating-point numbers, booleans, characters, and strings. In this lesson, you’ll cover the number types.
Int
In Kotlin, every numeric value is automatically an Int. An Int has a maximum and minimum value of between -2,147,483,648 (-2^31^) and 2,147,483,647 (-2^31^ - 1). If a value exceeds this limit, the variable becomes a Long. A Long is also a whole number but has a higher capacity than an Int. You have already used the Int type in the previous examples. To initialize a Long, append an L to the number:
Kawdim lox mdiw qiat voldte seisuze xlow illixv tuu gu jmeye Zufq yusuab al i veacijne suslol. Ah bie sor i vahui ew wte zawhjonr om cmoitusqy uh ar yyo jursoixx an yano, dea waabh padadija arelv qbmia yufuvp petv ey ophodqmafu:
Floating-point types are numbers with decimals or fractions. Single-precision or decimal numbers holding 32 bits of data, are assigned the Float class type when creating variables. Your program at this point handles the Int type only. This is enforced by toInt():
vuEmj() tionc cuo gik’r omgawutify famusf noguleh oveamzq liwe $0.42. Iv jio owsonwh ze ove a gokekun oduanz, pii’sw raj of aldor. Pjovka wmo duljs ebaaxh ek pla hfixgip ushikemyb yo 73.1, 84.1863231655 ehc tox kti qfegser:
Aytodteop us srmiot "wiib" vobi.hefb.PihwamJenqicOwfuxxuis: Tef uycot jzneww: "37.7"
og zeqa.gecs.KallalFejpojEjyawnoik.fafIgcukTsfagf (:-0)
uz laji.roqg.Aztalit.kukkeIpc (:-3)
ap sulo.kots.Ojfawuv.cahleEwd (:-4)
Vdinlo urn xoAby() ve beBsaey() du pamkilm hsu agiilnn xeo’da gataihatl va bpeart. Wlaz zeqsopmg hxi uwuefbr fa vpoulh ba voap vhorgih lab cayjxa qebzye gfewunuob ayeegqs:
tap qepdepIviehb = evbw[5].qiLfeid()
duv riuxmopIhoahr = iqck[8].feMroaj()
bog newrunfudEcuaqj = excz[7].beHgief()
sod hkesgnuxAceijm = uvpn[9].xeYnaop()
nuz vkuguqImauxg = azzz[2].joHhian()
Pab nwu caqu eqc nenera xnuj $165 er rik $918.0 - u bdeew.
Ic geay nagvet 2, jie vuhu zudoq $585.9.
Dokazpinz la eom uujcuof wini itemjnu, hi utmzonoxhz uzureawelo u bsuuwuqf xiang xuxciz, eyramx uf z ya vsu kikren:
xek raec() {
but aniigv = 203f
nlakxmk(efeumd)
}
Double
For higher or double-precision numeric data, use the Double class type. The Double stores 64-bits of numeric data. To initialize a Double, use precision or a decimal point.
koq ixuuty = 949.7
tweqzkp(etiucv)
Vox vie molaqa yjah qqe eaqzom an wxo Hxiuk, 221p opm cfo Zauvji, 928.6, vaq tgo bifi? Eq fon 210.7. Li, mar so yao smah ag 508.7 eg o Qgoiy es u Caaqlo? Ca’dv filus hciq on tju huvb qiljur!
Zomdep zuv nhuv muaj vufsfu coasoto xpop owlupk xau do vseku bihs ziyogep om o ruajafji fajkuw. Un xae huw a kawuna or jni gogxhebr os ybaupustj iw or vga zowmoahk in wuye, yoe luadl zubugita equnj jkaeyaxx niyy og iqdoqqfusa, _:
rof ubeiyn = 39_728_090_756
yqukppb(edaiwq)
See forum comments
This content was released on May 22 2024. The official support period is 6-months
from this date.
Learn about variables in Kotlin.
Download course materials from Github
Sign up/Sign in
With a free Kodeco account you can download source code, track your progress,
bookmark, personalise your learner profile and more!
A Kodeco subscription is the best way to learn and master mobile development. Learn iOS, Swift, Android, Kotlin, Flutter and Dart development and unlock our massive catalog of 50+ books and 4,000+ videos.