class String
Public Instance Methods
str_to_num()
click to toggle source
# File lib/kannum.rb, line 304 def str_to_num; KanNum.str_to_num self; end
to_fu()
click to toggle source
:method: to_fu
convert digit-string into float concerning with unit.
Args¶ ↑
none.
Return¶ ↑
A number in Float. If the original string has ‘%’, the number is divided by 100.0.
# File lib/digit_delim.rb, line 61 def to_fu ret = self.to_wof # if self =~ /%$/ then ret /= 100.0 else ret end case self when /%$/ ret /= 100.0 else ret end end
to_wof()
click to toggle source
w_dm(adp=-1, n=3)
click to toggle source
:method: w_dm
with delimiters: separate digit-string into each n-digits with delimiters.
Args¶ ↑
- adp
-
length of digits after the decimal point. (-1 if you want all of digits after the decimal point)
- n
-
the number of digits length of each separated string.
Return¶ ↑
separated string.
# File lib/digit_delim.rb, line 22 def w_dm(adp=-1, n=3) self.gsub( /(\d+)?(\.\d*)?/ ) { s1="#{$1}".dup; s2="#{$2}".dup; if s2.size != 0 if adp == -1 s2="#{s2}00".slice(0, s2.size) else s2="#{s2}00".slice(0, adp+1) end end s1.reverse.gsub( /\d{#{n}}(?=\d)/ ){|r| r+","}.reverse+s2 } end