Module: PositiveNumberSupport::FloatExt
- Defined in:
- lib/positive_number_support/float_ext.rb
文字列への変換 collapse
-
#pjust(int: 4, float: 3) ⇒ String (number)
rjust, ljust を用いて,小数点の桁揃えを行うメソッド.
桁数 (digit) collapse
-
#digit ⇒ Integer
整数部の桁数を取得するメソッド.
Instance Method Details
#digit ⇒ Integer
整数部の桁数を取得するメソッド
25 26 27 |
# File 'lib/positive_number_support/float_ext.rb', line 25 def digit ceil.digit end |
#pjust(int: 4, float: 3) ⇒ String (number)
rjust, ljust を用いて,小数点の桁揃えを行うメソッド
10 11 12 13 14 |
# File 'lib/positive_number_support/float_ext.rb', line 10 def pjust( int: 4 , float: 3 ) raise "Error: The variables \'int\' and \'float\' should be integer." unless [ int , float ].all?( &:integer? ) /\A(\d+)\.(\d+)/ =~ to_s $1.rjust( int ) + "\." + $2.ljust( float ) end |