pretty_floats 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (3) hide show
  1. checksums.yaml +7 -0
  2. data/lib/pretty_floats.rb +23 -0
  3. metadata +43 -0
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA256:
3
+ metadata.gz: ac694981f780e140d427ed58db1c226cd1bc861b1854301635d878fcf1b1072e
4
+ data.tar.gz: 0ac9e1aef495355ee7b2ad206c9bc038b01bbbd5fb33f35b585a7f4a98ee4e5e
5
+ SHA512:
6
+ metadata.gz: 5d403cc2ed314750ad9cc952d2de7fd9ac0b5da75662cb74963b28cbd46ac40c045b27f7480f1c75e4c554504b65e0905a9046770cd4054aba26b257a01930bd
7
+ data.tar.gz: ac96e21461da3027a84bea162bb2e8395a071ae301d36a6f78e5c524406141bd64cc5764b2015d763c21fb9494ca73d6c815baea2e400df35102738943fe6f33
@@ -0,0 +1,23 @@
1
+ class Float
2
+ # changes numbers like 1234567 to "1,234,567"
3
+ def prettify(place_sep=',', radix_sep='.')
4
+ int = self
5
+ .to_i
6
+ .to_s
7
+ .chars
8
+ .reverse
9
+ .each_slice(3)
10
+ .map{|slice| slice.join }
11
+ .join(place_sep)
12
+ .reverse
13
+
14
+ max_digits = self.to_s.split('.').last.length
15
+ float = (self % 1)
16
+ .round(max_digits)
17
+ .to_s
18
+ .split('.')
19
+ .last
20
+
21
+ int + radix_sep + float
22
+ end
23
+ end
metadata ADDED
@@ -0,0 +1,43 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: pretty_floats
3
+ version: !ruby/object:Gem::Version
4
+ version: 1.0.0
5
+ platform: ruby
6
+ authors:
7
+ - Jeff Lunt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2023-08-18 00:00:00.000000000 Z
12
+ dependencies: []
13
+ description: a small utility to format floating point numbers for easier reading
14
+ email: jefflunt@gmail.com
15
+ executables: []
16
+ extensions: []
17
+ extra_rdoc_files: []
18
+ files:
19
+ - lib/pretty_floats.rb
20
+ homepage: https://github.com/jefflunt/pretty_floats
21
+ licenses:
22
+ - MIT
23
+ metadata: {}
24
+ post_install_message:
25
+ rdoc_options: []
26
+ require_paths:
27
+ - lib
28
+ required_ruby_version: !ruby/object:Gem::Requirement
29
+ requirements:
30
+ - - ">="
31
+ - !ruby/object:Gem::Version
32
+ version: '0'
33
+ required_rubygems_version: !ruby/object:Gem::Requirement
34
+ requirements:
35
+ - - ">="
36
+ - !ruby/object:Gem::Version
37
+ version: '0'
38
+ requirements: []
39
+ rubygems_version: 3.4.1
40
+ signing_key:
41
+ specification_version: 4
42
+ summary: extends the Float class to add a few methods for inserting places separators
43
+ test_files: []