Make Numbers Pretty

This tutorial was inspired by the awesome Scala Cookbook.

Load The NumberFormat Library

// Make value that is assigned to an instance of numberformat
val make_pretty = java.text.NumberFormat.getInstance

Make An Integer Pretty

// Format 10000 to 10,000
make_pretty.format(10000)

Make A Float Pretty

// Format to 10000.1928 to 10,000.193
make_pretty.format(10000.1928)
10,000.193

Load The NumberFortmat Library Set For European Numbers

// Set the locale to germany
val germany = new java.util.Locale("de", "DE")

// Make value that is assigned to an instance of numberformat set to germany
val make_pretty_de = java.text.NumberFormat.getIntegerInstance(germany)

Make An Integer Pretty

// Format 1000000 to 1.000.000
make_pretty_de.format(1000000)
1.000.000