bigdecimal_places 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +4 -0
- data/lib/bigdecimal_places.rb +13 -0
- metadata +57 -0
data/README
ADDED
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'bigdecimal'
|
2
|
+
|
3
|
+
class BigDecimal
|
4
|
+
def to_places(places)
|
5
|
+
multiplier = 10**places.to_i
|
6
|
+
units = self * multiplier
|
7
|
+
whole_units = units.round(0,BigDecimal::ROUND_DOWN).to_i
|
8
|
+
difference = units.frac
|
9
|
+
whole_units +=1 if difference > 0.5
|
10
|
+
whole_units +=1 if (difference == 0.5) && (whole_units.modulo(2)==1)
|
11
|
+
BigDecimal.new(whole_units.to_s) / multiplier
|
12
|
+
end
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,57 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: bigdecimal_places
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease:
|
5
|
+
version: 0.1.0
|
6
|
+
platform: ruby
|
7
|
+
authors:
|
8
|
+
- Clive Andrews
|
9
|
+
autorequire:
|
10
|
+
bindir: bin
|
11
|
+
cert_chain: []
|
12
|
+
|
13
|
+
date: 2011-11-23 00:00:00 +01:00
|
14
|
+
default_executable:
|
15
|
+
dependencies: []
|
16
|
+
|
17
|
+
description: BigDecimal financial rounding with to_places(n) method
|
18
|
+
email: pacman@realitybites.nl
|
19
|
+
executables: []
|
20
|
+
|
21
|
+
extensions: []
|
22
|
+
|
23
|
+
extra_rdoc_files:
|
24
|
+
- README
|
25
|
+
files:
|
26
|
+
- lib/bigdecimal_places.rb
|
27
|
+
- README
|
28
|
+
has_rdoc: true
|
29
|
+
homepage:
|
30
|
+
licenses: []
|
31
|
+
|
32
|
+
post_install_message:
|
33
|
+
rdoc_options: []
|
34
|
+
|
35
|
+
require_paths:
|
36
|
+
- lib
|
37
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ">="
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
version: "0"
|
43
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
44
|
+
none: false
|
45
|
+
requirements:
|
46
|
+
- - ">="
|
47
|
+
- !ruby/object:Gem::Version
|
48
|
+
version: "0"
|
49
|
+
requirements: []
|
50
|
+
|
51
|
+
rubyforge_project:
|
52
|
+
rubygems_version: 1.6.2
|
53
|
+
signing_key:
|
54
|
+
specification_version: 3
|
55
|
+
summary: BigDecimal financial rounding
|
56
|
+
test_files: []
|
57
|
+
|