[SNIPPET] Rounding numbers (for ratings)
Posted: 24 Jul 2012, 03:43
Here's some code that'll show you how to round numbers in Groovy.
e.g. round to nearest Integer and format as Integer, i.e. 7, 8, 9, ...
e.g. round to nearest Integer and format as Decimal, i.e. 7.0, 8.0, 9.0, ...
e.g. round to the nearest 1/10 fraction, i.e. 7.1, 8.2, 9.3, ...
e.g. round to nearest Integer and format as Integer, i.e. 7, 8, 9, ...
Format: Select all
{ rating.round() }
e.g. round to nearest Integer and format as Decimal, i.e. 7.0, 8.0, 9.0, ...
Format: Select all
{ rating.round(0) }
e.g. round to the nearest 1/10 fraction, i.e. 7.1, 8.2, 9.3, ...
Format: Select all
{ rating.round(1) }