Haha TTpro
Haha TTpro

Reputation: 5546

How to cast Int to BigInt in Scala

I have Int

val y = 10

I want to cast to BigInt

y.toBigInt 

it show error

<console>:26: error: value toBigInt is not a member of Int
       y.toBigInt

How can I cast Int to BigInt ?

Upvotes: 0

Views: 7866

Answers (2)

Tim
Tim

Reputation: 27356

All the obvious methods work. You can assign an Int to a BigInt, you can pass an Int to a function that takes BigInt, and you can just use BigInt(y).

Upvotes: 4

talex
talex

Reputation: 20436

Here is example:

val i: Int = 1
val bigInt = BigInt(i)

Upvotes: 8

Related Questions