3

I have a number, I want to pad this number with zero's in the beginning if the digits are less that 9 digits.

currently if I have a number lets say:

val num = "123"

if I use padTo(9,"0") I will get "123000000" but I want "000000123"...

what is the best solution for this?

would be better to get the solution in scala

thanks

Joe
  • 2,543
  • 3
  • 25
  • 49
  • 3
    its not duplicate cause my number is string and not an int @Tunaki – Joe Mar 01 '16 at 14:06
  • 2
    There are other answers that cover this case, like this one http://stackoverflow.com/a/8131372/1743880 – Tunaki Mar 01 '16 at 14:07
  • 1
    this is not a good solution, using revers on the string and then another revers its a hack @Tunaki – Joe Mar 01 '16 at 16:17
  • 1
    How about the answer to this [question](https://stackoverflow.com/questions/388461/how-can-i-pad-a-string-in-java): `String.format("%9s", "123").replace(' ', '0');` ? Or do you consider that to also be a hack? – Abra Oct 21 '21 at 13:36

0 Answers0