Class: Float
- Inherits:
-
Object
- Object
- Float
- Defined in:
- lib/options-lib/helpers.rb
Instance Method Summary collapse
-
#prettify ⇒ Object
Supress decimal part if it is zero 40.0 becomes "40" Take care of float imprecision 1.1-0.9 # >> 0.20000000000000007 (1.1-0.9).prettify # >> "0.2".
Instance Method Details
#prettify ⇒ Object
Supress decimal part if it is zero 40.0 becomes "40" Take care of float imprecision 1.1-0.9 # >> 0.20000000000000007 (1.1-0.9).prettify # >> "0.2"
8 9 10 11 12 13 14 |
# File 'lib/options-lib/helpers.rb', line 8 def prettify num = "%.12g" % self num.sub!($1, '') if num =~ /\..*?(0+)$/ # might be like 2. at this point num = num[0..-2] if num[-1] == '.' num end |