Round a ruby float up or down to the nearest 0.05

后端 未结 9 1671
日久生厌
日久生厌 2020-12-29 04:43

I\'m getting numbers like

2.36363636363636
4.567563
1.234566465448465
10.5857447736

How would I get Ruby to round these numbers up (or dow

9条回答
  •  醉梦人生
    2020-12-29 04:55

    It’s possible to round numbers with String class’s % method.

    For example

    "%.2f" % 5.555555555
    

    would give "5.56" as result (a string).

提交回复
热议问题