Int, Double, Float और Long
Int, Double, Float, और Long अलग-अलग size के number boxes हैं: छोटी whole numbers, बड़ी whole numbers, और decimals वाली numbers। आप अपनी number के हिसाब से box चुनते हैं।
In this page:
Syntax
val i: Int = 42
val l: Long = 42L
val d: Double = 3.14
val f: Float = 3.14f
Int, Double, Float, Long
Int एक 32-bit whole number है, Long इसे 64 bits तक बढ़ाता है (literals पर L suffix के साथ), और Double/Float क्रमशः 64-bit और 32-bit floating-point numbers को represent करते हैं (Float literals के लिए f suffix के साथ)।
Double, decimal literals के लिए default type है जब तक specifically Float की मांग न की जाए। सही numeric type चुनना precision और memory usage दोनों के लिए मायने रखता है।
Note:
बिना explicit type annotation या suffix के,
3.14 जैसा decimal literal Float नहीं बल्कि Double के रूप में inferred होता है।उदाहरण: Int, Double, Float, Long
object Main extends App {
val age: Int = 30
val population: Long = 8000000000L
val price: Double = 19.99
val temperature: Float = 36.6f
println(s"$age $population $price $temperature")
}
Login to try C/C++/Java/PHP code in the editor
Related Topics
{# common_mistakes/chapter_summary/browser_support: on Hindi pages the
view already swaps in the hi_ translation fields (or blanks these
out if untranslated), so this renders correctly for both languages
without a lang_code check here. #}
आम गलतियां
val big: Long = 8000000000जैसी बड़ी number को बिनाLके store करना, जिससेinteger number too largeerror आता है।val f: Float = 36.6को बिनाfके लिखना, जिससे type error आता है क्योंकि36.6एकDoubleहै।7 / 2जैसी दोIntvalues को divide करना और3.5की उम्मीद करना, जबकि यह3देता है।
🔒
Chapter Quiz — Complete all 8 topics to unlock
0/8 topics done
Complete these topics first: