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

Popular posts from this blog

ruby - When to use an ORM (Sequel, Datamapper, AR, etc.) vs. pure SQL for querying -

php - PHPDoc: @return void necessary? -

c++ - Convert big endian to little endian when reading from a binary file -