Skip to content
This repository has been archived by the owner on Mar 30, 2024. It is now read-only.

Commit

Permalink
Merge pull request #76 from green-energy-trading/fix-numeric-with-lea…
Browse files Browse the repository at this point in the history
…ding-zero-fractional

Fix numeric with leading zero fractional
  • Loading branch information
vzsg authored May 22, 2018
2 parents 16f64dd + 536842e commit 1d23662
Show file tree
Hide file tree
Showing 2 changed files with 4 additions and 3 deletions.
6 changes: 3 additions & 3 deletions Sources/PostgreSQL/Bind/BinaryUtils.swift
Original file line number Diff line number Diff line change
Expand Up @@ -175,7 +175,7 @@ struct BinaryUtils {
digits = (0..<numberOfDigits).map { BinaryUtils.parseInt16(value: value.advanced(by: 8 + $0 * 2)) }
}

private func getDigit(atIndex index: Int) -> String {
private func getDigit(atIndex index: Int, fractional: Bool = false) -> String {
let int16: Int16
if index >= 0 && index < numberOfDigits {
int16 = digits[index]
Expand All @@ -184,7 +184,7 @@ struct BinaryUtils {
}
let stringDigits = String(int16)

guard index != 0 else {
if (index == 0 && !fractional) {
return stringDigits
}

Expand Down Expand Up @@ -302,7 +302,7 @@ struct BinaryUtils {
let decimalIndex = string.endIndex

for _ in stride(from: 0, to: dscale, by: Numeric.decDigits) {
string += getDigit(atIndex: digitIndex)
string += getDigit(atIndex: digitIndex, fractional: true)
digitIndex += 1
}

Expand Down
1 change: 1 addition & 0 deletions Tests/PostgreSQLTests/PostgreSQLTests.swift
Original file line number Diff line number Diff line change
Expand Up @@ -281,6 +281,7 @@ class PostgreSQLTests: XCTestCase {
let rows: [String] = [
"0",
"0.1",
"10.08",
"-0.123",
"123",
"456.7891412341",
Expand Down

0 comments on commit 1d23662

Please sign in to comment.