[SNIPPET] Rounding numbers (for ratings)

All about user-defined episode / movie format expressions
Post Reply
User avatar
rednoah
The Source
Posts: 21687
Joined: 16 Nov 2011, 08:59

[SNIPPET] Rounding numbers (for ratings)

Post by rednoah »

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, ...

Code: Select all

{ rating.round() }

e.g. round to nearest Integer and format as Decimal, i.e. 7.0, 8.0, 9.0, ...

Code: Select all

{ rating.round(0) }

e.g. round to the nearest 1/10 fraction, i.e. 7.1, 8.2, 9.3, ...

Code: Select all

{ rating.round(1) }
:idea: Please read the FAQ and How to Request Help.
Post Reply