def multiplyStringNumericChars(list: String): Int = {
var product = 1;
println(s"The actual thing + $list")
list.foreach(x => { println(x.toInt);
product = product * x.toInt;
});
product;
};
This is a function that takes a String like 12345
and should return the result of 1 * 2 * 3 * 4 * 5
. However, I'm getting back doesn't make any sense. What is the implicit conversion from Char
to Int
actually returning?
It appears to be adding 48
to all the values. If instead I do product = product * (x.toInt - 48)
the results are correct.