Rounding float in Ruby -
i'm having problems rounding. have float, want round hundredth of decimal. however, can use .round
turns int, meaning 2.34.round # => 2.
there simple effect way 2.3465 # => 2.35
when displaying, can use (for example)
>> '%.2f' % 2.3465 => "2.35"
if want store rounded, can use
>> (2.3465*100).round / 100.0 => 2.35
Comments
Post a Comment