Answer the question
In order to leave comments, you need to log in
Answer the question
In order to leave comments, you need to log in
a = 1.234
b = 5
(a - b).round # -4
(a - b).round(1) # -3.8
(a - b).round(2) # -3.77
(a - b).round(3) # -3.766
a = 1.234
b = 5
c = a - b
sprintf("%.f", c) # "-4"
sprintf("%.1f", c) # "-3.8"
sprintf("%.2f", c) # "-3.77"
sprintf("%.3f", c) # "-3.766"
sprintf("%.4f", c) # "-3.7660"
Didn't find what you were looking for?
Ask your questionAsk a Question
731 491 924 answers to any question