1

Below are my 2 functions

def getProductAsDouble(nums: Double*):Double={
    var n = new BigDecimal("1.0")
    nums.foreach(num => n = n.multiply(new BigDecimal(num.toString)))
    n.setScale(2,java.math.BigDecimal.ROUND_HALF_UP).doubleValue()
  }

  def getProductAsString(nf:NumberFormat,nums: Double*): String ={
    nf.format(getProductAsDouble(nums)) // shows error here
  }

I am unable to pass nums from getProductAsString to getProductAsDouble. Is there any way to resolve this?

CS1999
  • 303
  • 2
  • 10

1 Answers1

3

You can use : _*

e.g.

def getProductAsString(nf:NumberFormat,nums: Double*): String ={
  nf.format(getProductAsDouble(nums : _*))
}

There is a good explanation of _* type annotation here: What does `:_*` (colon underscore star) do in Scala?

AlexV
  • 449
  • 3
  • 6