i want to round off a number upto two decimal place in ruby such that
(0.02 * 270187).round(2)
is 5403.74 which is correct
but
(0.02 * 278290).round(2)
is 5565.8 which is not consistent with previous one
i want to make it look like 5565.80
Please tell me how can i do it in ruby
You could do something like
include ActionView::Helpers::NumberHelper
number_with_precision(value, :precision => 2) # value.to_f if you have string
or like this
'%.2f' % your_value
Hope it helps! Further you can read from here
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With