I have a BigDecimal calculation result which I need to round to the nearest specified interval (in this case it's the financial market tick size).
e.g. Price [Tick Size] -> Rounded Price
100.1 [0.25] -> 100
100.2 [0.25] -> 100.25
100.1 [0.125] -> 100.125
100.2 [0.125] -> 100.25
Thanks.
Update: schnaader's solution, translated into Java/BigDecimal terms:
price = price.divide(tick).setScale(0, RoundingMode.HALF_UP).multiply(tick)