core_extend 0.1.2 → 0.1.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 7affb16c4c306cbc66c58037215d1bcdf1ef332b
4
- data.tar.gz: c6eb4626d0124eb516fc85eb0d2bfdc0bc934e52
3
+ metadata.gz: 8618ac69020c0bab44a6edd543a856ba0171c7ca
4
+ data.tar.gz: a4955a463de873673ecb1b72aa394947170df69a
5
5
  SHA512:
6
- metadata.gz: 257b654f6cb1724d87380e78611ebfb1b7c4e8a7305a0a30cce1616f2f37b1423a17288bf36d445eb771bc8ec3315ab668497c5f6ae933aa9baf141e0ad3bfc5
7
- data.tar.gz: 6b2365dd77d4d3261e3c9bfe6e01b70cb91f6695b392c26fc7c2888457f8f5b8b13cb52d4e35a5e1ea9ae28e788897dcb2135bafdfda1dad5870dba20b3f1dda
6
+ metadata.gz: a6e7e46a3a8cb5e38ef174c14802d13de6a48b2e1e23b4136048e99101986a62d4f7492bc595babc7d288ecd105ae75c77d0ffc94faeb531b7b929b40dcf850c
7
+ data.tar.gz: 871df135903b64ee3cfbc19028359a7102b35b03335dff6e270e02390559ac9b6a7e3a705a5085e1275f3c9bb8a4a7358962d5529ffd0b2cd9523dcc7862d304
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- core_extend (0.1.0)
4
+ core_extend (0.1.2)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
data/lib/core_extend.rb CHANGED
@@ -1,4 +1,5 @@
1
- require "core_extend/version"
1
+ require 'core_extend/version'
2
+ require 'core_extend/float_module'
2
3
 
3
4
  Dir.glob("#{File.dirname(__FILE__)}/core_extend/*.rb") { |f| require f }
4
5
 
@@ -0,0 +1,3 @@
1
+ class BigDecimal
2
+ include CoreExtend::FloatModule
3
+ end
@@ -1,35 +1,4 @@
1
1
  class Float
2
-
3
- #保留小数点位数
4
- def decimal_point(point=2)
5
- sprintf("%0.#{point}f", self).to_f
6
- end
7
-
8
- #显示成钱数
9
- #===Parameters
10
- # +type+ enum 'num','text'
11
- #===Returns
12
- # +string+
13
- def to_money(type='num',point=2)
14
- str = decimal_point(point).to_s
15
- int_str = str.split('.')[0]
16
- point_str = str.split('.')[1]
17
-
18
- if type=='text'
19
- return "#{int_str}.#{point_str}" if int_str.to_i<10000
20
-
21
- return "#{(int_str.to_i/10000.0).decimal_point(point)}万" if int_str.to_i<100000000
22
-
23
- return "#{(int_str.to_i/100000000.0).decimal_point(point)}亿"
24
- end
25
-
26
- return "#{int_str}.#{point_str}" if int_str.length<3
27
- index = -4
28
- while index.abs < int_str.length+1
29
- int_str.insert(index, ',')
30
- index -=4
31
- end
32
- "#{int_str}.#{point_str}"
33
- end
2
+ include CoreExtend::FloatModule
34
3
 
35
4
  end
@@ -0,0 +1,36 @@
1
+ module CoreExtend
2
+ module FloatModule
3
+
4
+ #保留小数点位数
5
+ def decimal_point(point=2)
6
+ sprintf("%0.#{point}f", self).to_f
7
+ end
8
+
9
+ #显示成钱数
10
+ #===Parameters
11
+ # +type+ enum 'num','text'
12
+ #===Returns
13
+ # +string+
14
+ def to_money(type='num', point=2)
15
+ str = decimal_point(point).to_s
16
+ int_str = str.split('.')[0]
17
+ point_str = str.split('.')[1]
18
+
19
+ if type=='text'
20
+ return "#{int_str}.#{point_str}" if int_str.to_i<10000
21
+
22
+ return "#{(int_str.to_i/10000.0).decimal_point(point)}万" if int_str.to_i<100000000
23
+
24
+ return "#{(int_str.to_i/100000000.0).decimal_point(point)}亿"
25
+ end
26
+
27
+ return "#{int_str}.#{point_str}" if int_str.length<3
28
+ index = -4
29
+ while index.abs < int_str.length+1
30
+ int_str.insert(index, ',')
31
+ index -=4
32
+ end
33
+ "#{int_str}.#{point_str}"
34
+ end
35
+ end
36
+ end
@@ -1,3 +1,3 @@
1
1
  module CoreExtend
2
- VERSION = '0.1.2'
2
+ VERSION = '0.1.3'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: core_extend
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - saxer
@@ -57,7 +57,9 @@ files:
57
57
  - core_extend.gemspec
58
58
  - lib/core_extend.rb
59
59
  - lib/core_extend/array.rb
60
+ - lib/core_extend/big_decimal.rb
60
61
  - lib/core_extend/float.rb
62
+ - lib/core_extend/float_module.rb
61
63
  - lib/core_extend/version.rb
62
64
  homepage: https://github.com/mumaoxi/core_extend
63
65
  licenses: