gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[taler-taler-ios] 30/36: Bugfix


From: gnunet
Subject: [taler-taler-ios] 30/36: Bugfix
Date: Mon, 13 Nov 2023 21:27:35 +0100

This is an automated email from the git hooks/post-receive script.

marc-stibane pushed a commit to branch master
in repository taler-ios.

commit 4d6934bfd34c917b5f9d3c1fc7424999f3de184a
Author: Marc Stibane <marc@taler.net>
AuthorDate: Mon Nov 13 20:46:37 2023 +0100

    Bugfix
---
 taler-swift/Sources/taler-swift/Amount.swift | 29 +++++++++++++++++++++++-----
 1 file changed, 24 insertions(+), 5 deletions(-)

diff --git a/taler-swift/Sources/taler-swift/Amount.swift 
b/taler-swift/Sources/taler-swift/Amount.swift
index 86814f7..1751b20 100644
--- a/taler-swift/Sources/taler-swift/Amount.swift
+++ b/taler-swift/Sources/taler-swift/Amount.swift
@@ -140,15 +140,34 @@ public final class Amount: Codable, Hashable, @unchecked 
Sendable, CustomStringC
     /// The string representation of the value, formatted as 
"`integer``fraction`",
     /// no group separator, no decimalSeparator, #inputDigits digits from 
fraction, padded with trailing zeroes
     public func plainString(inputDigits: UInt) -> String {
+        let base = fractionalBase()
         var frac = fraction
         var fracStr = ""
         var i = inputDigits
-        while (i > 0) {
-            fracStr += String(frac / (fractionalBase() / 10))
-            frac = (frac * 10) % fractionalBase()
-            i -= 1
+
+        var nextchar: UInt32 {
+            let fracChar = frac / (base / 10)
+            frac = (frac * 10) % base
+            return fracChar
+        }
+
+        if integer > 0 {
+            while (i > 0) {
+                fracStr += String(nextchar)
+                i -= 1
+            }
+            return "\(integer)\(fracStr)"
+        } else {
+            while (i > 0) {
+                let fracChar = nextchar
+                // skip leading zeroes
+                if fracStr.count > 0 || fracChar > 0 {
+                    fracStr += String(fracChar)
+                }
+                i -= 1
+            }
+            return fracStr.count > 0 ? fracStr : "0"
         }
-        return "\(integer)\(fracStr)"
     }
 
     /// read-only getter

-- 
To stop receiving notification emails like this one, please contact
gnunet@gnunet.org.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]