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 +4 -4
- data/Gemfile.lock +1 -1
- data/lib/core_extend.rb +2 -1
- data/lib/core_extend/big_decimal.rb +3 -0
- data/lib/core_extend/float.rb +1 -32
- data/lib/core_extend/float_module.rb +36 -0
- data/lib/core_extend/version.rb +1 -1
- metadata +3 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 8618ac69020c0bab44a6edd543a856ba0171c7ca
|
4
|
+
data.tar.gz: a4955a463de873673ecb1b72aa394947170df69a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a6e7e46a3a8cb5e38ef174c14802d13de6a48b2e1e23b4136048e99101986a62d4f7492bc595babc7d288ecd105ae75c77d0ffc94faeb531b7b929b40dcf850c
|
7
|
+
data.tar.gz: 871df135903b64ee3cfbc19028359a7102b35b03335dff6e270e02390559ac9b6a7e3a705a5085e1275f3c9bb8a4a7358962d5529ffd0b2cd9523dcc7862d304
|
data/Gemfile.lock
CHANGED
data/lib/core_extend.rb
CHANGED
data/lib/core_extend/float.rb
CHANGED
@@ -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
|
data/lib/core_extend/version.rb
CHANGED
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.
|
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:
|