Here is how my method is currently defined in Scala, i've been following this Stackoverflow answer
def digitFormatter(long: Long, numDigits: Int): String = {
String.format(s"%0${numDigits}d", long)
}
This seems to work ok with postive integers, i get this expected behavior
assert(digitFormatter(0, 1) == "0")
assert(digitFormatter(0, 2) == "00")
assert(digitFormatter(1, 2) == "01")
assert(digitFormatter(10, 2) == "10")
However this doesn't seem to work with negative numbers, this is what I would expect my output to be
assert(
digitFormatter(-1, 2) == "-01")
However the result I get is just -1
. How do I pad leading zeroes on negative numbers using the java std libraries?