zipdatev 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 93a524d3a6c114e4ba449add730c39e4db83007ff043ef1b0e734786b4f56c1f
|
|
4
|
+
data.tar.gz: be5eb61e54fb13aca8fc308286c6ca02b5302f1663217b5470770e4e7fe786be
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 3637481aa9773fcdc5458ecbdced141d9fa817fc6098df825b6e395fcee5fa0f92ce33ab18d6bef5d8d499f037a19f691f5f4873b44bee233c4280393c6c973b
|
|
7
|
+
data.tar.gz: 87d7e721150ac9771e7ec9bc20d1c7a2569a2c9736cd30ff9b8b071e269571b30f8c8dda538436155b06f54d0eb1889523fb09ed8adbd85d06cadb8fa806148e
|
|
@@ -1,5 +1,6 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require "bigdecimal"
|
|
3
4
|
require "nokogiri"
|
|
4
5
|
require "active_support/core_ext/string/inflections"
|
|
5
6
|
|
|
@@ -82,13 +83,19 @@ module ZipDatev
|
|
|
82
83
|
|
|
83
84
|
# Format a decimal value for XML output with specified precision
|
|
84
85
|
#
|
|
86
|
+
# Uses BigDecimal's string representation to avoid floating point artifacts
|
|
87
|
+
# from format()/sprintf(), which implicitly convert BigDecimal to Float.
|
|
88
|
+
#
|
|
85
89
|
# @param value [BigDecimal, Numeric, nil] The value to format
|
|
86
90
|
# @param precision [Integer] Number of decimal places (default: 2)
|
|
87
91
|
# @return [String, nil] Formatted decimal string or nil if value is nil
|
|
88
92
|
def format_decimal(value, precision: 2)
|
|
89
93
|
return nil if value.nil?
|
|
90
94
|
|
|
91
|
-
|
|
95
|
+
decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
|
|
96
|
+
str = decimal.round(precision).to_s("F")
|
|
97
|
+
integer_part, fractional_part = str.split(".")
|
|
98
|
+
"#{integer_part}.#{(fractional_part || "").ljust(precision, "0")}"
|
|
92
99
|
end
|
|
93
100
|
|
|
94
101
|
# Convert a Ruby snake_case symbol to XML camelCase element name
|
|
@@ -36,9 +36,9 @@ class DecimalPrecisionValidator < ActiveModel::EachValidator
|
|
|
36
36
|
# Convert to BigDecimal for consistent handling
|
|
37
37
|
decimal = value.is_a?(BigDecimal) ? value : BigDecimal(value.to_s)
|
|
38
38
|
|
|
39
|
-
# Use string representation to
|
|
40
|
-
#
|
|
41
|
-
str =
|
|
39
|
+
# Use BigDecimal's string representation to avoid floating point artifacts
|
|
40
|
+
# BigDecimal#to_s("F") returns a fixed-point string like "12691.72"
|
|
41
|
+
str = decimal.to_s("F")
|
|
42
42
|
parts = str.split(".")
|
|
43
43
|
|
|
44
44
|
return places.zero? if parts.length == 1
|
data/lib/zipdatev/version.rb
CHANGED