to Big Integer
Начиная с Kotlin: 1.2
inline fun Int.toBigInteger(): BigInteger
Возвращает значение этого числа Int в виде BigInteger.
Примеры
fun main() {
//sampleStart
println(42.toBigInteger()) // 42
println(Int.MAX_VALUE.toBigInteger()) // 2147483647
println(Int.MIN_VALUE.toBigInteger()) // -2147483648
// BigInteger can hold values beyond Int range
println(Int.MAX_VALUE.toBigInteger() * 10.toBigInteger()) // 21474836470
//sampleEnd
}
inline fun Long.toBigInteger(): BigInteger
Возвращает значение этого числа Long в виде BigInteger.
Примеры
fun main() {
//sampleStart
println(42L.toBigInteger()) // 42
println(Long.MAX_VALUE.toBigInteger()) // 9223372036854775807
println(Long.MIN_VALUE.toBigInteger()) // -9223372036854775808
// BigInteger can hold values beyond Long range
println(Long.MAX_VALUE.toBigInteger() * 10.toBigInteger()) // 92233720368547758070
//sampleEnd
}
inline fun UInt.toBigInteger(): BigInteger
Возвращает значение этого числа UInt в виде BigInteger.
Примеры
fun main() {
//sampleStart
println(42u.toBigInteger()) // 42
println(UInt.MAX_VALUE.toBigInteger()) // 4294967295
// BigInteger can hold values beyond UInt range
println(UInt.MAX_VALUE.toBigInteger() * 10.toBigInteger()) // 42949672950
//sampleEnd
}
fun ULong.toBigInteger(): BigInteger
Возвращает значение этого числа ULong в виде BigInteger.
Примеры
fun main() {
//sampleStart
println(42uL.toBigInteger()) // 42
println(ULong.MAX_VALUE.toBigInteger()) // 18446744073709551615
// BigInteger can hold values beyond ULong range
println(ULong.MAX_VALUE.toBigInteger() * 10.toBigInteger()) // 184467440737095516150
//sampleEnd
}
© 2010–2026 JetBrains s.r.o. and Kotlin Programming Language contributors
Licensed under the Apache License, Version 2.0.
https://kotlinlang.org/api/core/kotlin-stdlib/kotlin/to-big-integer.html