Little break from the heavy stuff !
Let's see an example on how some Java
features have been integrated in Scala. Specially about String formatting at the moment.
This SKB is about formatting numbers.
In the first example, we are seeing how to add leading zeros in front of a number. That can be useful when building some UI or dashboard so the alignment is fix no matter how big the number is. Pretty useful and easy to use !
Then formatting Double
, how to truncate the decimals as well as adding leading zeros. Play with it to get a good intuition about it.
And finally, getting closer to Java
with Locale
which allow you to display a number the right way based on the location. Locale
can also be used to format dates and currencies ! Feel free to search for more information online and try to implement the code in here.