istox 0.1.156.3 → 0.1.156.4
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.idea/istox-gem.iml +2 -1852
- data/lib/istox/helpers/formatter.rb +6 -4
- data/lib/istox/version.rb +1 -1
- metadata +6 -6
@@ -2,21 +2,23 @@ module Istox
|
|
2
2
|
class Formatter
|
3
3
|
class << self
|
4
4
|
# format a number, eg. 20000.134 > 20,000.14
|
5
|
-
def number(input, round_mode: :half_up, precision: 2)
|
5
|
+
def number(input, round_mode: :half_up, precision: 2, abs_num: false)
|
6
6
|
BigDecimal.mode(BigDecimal::ROUND_MODE, round_mode)
|
7
7
|
|
8
8
|
input = 0 if input.blank?
|
9
9
|
|
10
10
|
input = ::BigDecimal.new(input.to_s).round(precision, round_mode)
|
11
11
|
|
12
|
+
input = input.abs if abs_num
|
13
|
+
|
12
14
|
result = format("%.#{precision}f", input)
|
13
15
|
|
14
16
|
result.to_s.reverse.gsub(/(\d{3})(?=\d)/, '\\1,').reverse
|
15
17
|
end
|
16
18
|
|
17
|
-
# format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind
|
18
|
-
def money(input, round_mode: :half_up, precision: 2, currency:, position: :front)
|
19
|
-
result = number(input, round_mode: round_mode, precision: precision)
|
19
|
+
# format a money, eg. 20000.134 > SGD 20,000.14, position can be :front or :behind, abs_num: whether to absolute the number
|
20
|
+
def money(input, round_mode: :half_up, precision: 2, currency:, position: :front, abs_num: false)
|
21
|
+
result = number(input, round_mode: round_mode, precision: precision, abs_num: abs_num)
|
20
22
|
|
21
23
|
return currency + ' ' + result if position == :front
|
22
24
|
|
data/lib/istox/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: istox
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1.156.
|
4
|
+
version: 0.1.156.4
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Siong Leng
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2020-07-
|
11
|
+
date: 2020-07-28 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: amazing_print
|
@@ -524,7 +524,7 @@ files:
|
|
524
524
|
homepage: http://www.abc.com
|
525
525
|
licenses: []
|
526
526
|
metadata: {}
|
527
|
-
post_install_message:
|
527
|
+
post_install_message:
|
528
528
|
rdoc_options: []
|
529
529
|
require_paths:
|
530
530
|
- lib
|
@@ -539,8 +539,8 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
539
539
|
- !ruby/object:Gem::Version
|
540
540
|
version: '0'
|
541
541
|
requirements: []
|
542
|
-
rubygems_version: 3.0.
|
543
|
-
signing_key:
|
542
|
+
rubygems_version: 3.0.6
|
543
|
+
signing_key:
|
544
544
|
specification_version: 4
|
545
545
|
summary: istox backend shared gem
|
546
546
|
test_files: []
|