How to use BigDecimal In Scala

Below is the Scala program to implement exponentiation using BigDecimal:

Scala
//Scala Program to use Exponential
import scala.math.BigDecimal

val base = 3
val exponent = 4

val result = BigDecimal(base).pow(exponent)

println(result)

Output:

81

How to do Exponentiation in Scala?

This article focuses on discussing implementing exponentiation in Scala. The math.pow() function from the scala.math package is used for exponentiation in Scala.

Table of Content

  • Basic Approach
  • Using BigDecimal
  • With Long Data Types

Syntax: 

val result = pow(base, exponent)

Similar Reads

Basic Approach

Below is the Scala program to implement exponentiation:...

Using BigDecimal

Below is the Scala program to implement exponentiation using BigDecimal:...

With Long Data Types

Below is the Scala program to implement exponentiation with long data types:...