pretty_floats 1.0.0 → 2.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/pretty_floats.rb +8 -6
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c55d7ddbb44134dd3c5b5d1798f27cf6f2f7244aad99cde2713a09d60298661b
|
4
|
+
data.tar.gz: 2961c06fe81b65aa3ac9ec132eceb0de2173e2ed226697601bf7c0d9c0ea01f0
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 4f9add340af35497dd115f8f0d6db78a1b44d93b2ed49d133c76ddda4c404771528a4d5203427a30b26658e6e39244a3c38e3685c360cf81c57fb1865a857961
|
7
|
+
data.tar.gz: 648e44584e753f965bc6a87108c4acd524e0fe97cc3b4c7605a10f5dce7fbd69176765a7674f9abf53fa628e660b566a29fe4be760ffc1412a1200ab8fae8bed
|
data/lib/pretty_floats.rb
CHANGED
@@ -1,7 +1,10 @@
|
|
1
1
|
class Float
|
2
2
|
# changes numbers like 1234567 to "1,234,567"
|
3
|
-
def prettify(place_sep
|
3
|
+
def prettify(place_sep: ',', radix_sep: '.', num_places: -1)
|
4
|
+
sign = self < 0 ? '-' : ''
|
5
|
+
|
4
6
|
int = self
|
7
|
+
.abs
|
5
8
|
.to_i
|
6
9
|
.to_s
|
7
10
|
.chars
|
@@ -11,13 +14,12 @@ class Float
|
|
11
14
|
.join(place_sep)
|
12
15
|
.reverse
|
13
16
|
|
14
|
-
|
15
|
-
float =
|
16
|
-
|
17
|
-
.to_s
|
17
|
+
max_precision = num_places == -1 ? self.to_s.split('.').last.length : num_places
|
18
|
+
float = self % 1
|
19
|
+
float = ("%.#{max_precision}f" % float)
|
18
20
|
.split('.')
|
19
21
|
.last
|
20
22
|
|
21
|
-
int + radix_sep + float
|
23
|
+
sign + int + radix_sep + float
|
22
24
|
end
|
23
25
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: pretty_floats
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
4
|
+
version: 2.1.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jeff Lunt
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2023-
|
11
|
+
date: 2023-09-16 00:00:00.000000000 Z
|
12
12
|
dependencies: []
|
13
13
|
description: a small utility to format floating point numbers for easier reading
|
14
14
|
email: jefflunt@gmail.com
|