Following code is used to rounding-off any floating numbers with specified decimal places. There is also helper method provided by rails to do the same which is "number_with_precision". But if we want to rounding-off the floating number in controller, then following one-liner code may be helpful for that case.
# Specify your number to be round-off instead of FLOATING_NUMBER and how many decimal places you want instead of i.
No comments:
Post a Comment