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

C#: Application without a window or taskbar item (background app) that can still use Console.WriteLine() -

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

openssl - Load PKCS#8 binary key into Ruby -