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.
@@ -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
 
@@ -1,3 +1,3 @@
1
1
  module Istox
2
- VERSION = '0.1.156.3'.freeze
2
+ VERSION = '0.1.156.4'.freeze
3
3
  end
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.3
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-15 00:00:00.000000000 Z
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.8
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: []