]> git.ktnx.net Git - mobile-ledger.git/blobdiff - app/src/main/java/net/ktnx/mobileledger/model/LedgerTransactionAccount.java
use locale-aware String.format
[mobile-ledger.git] / app / src / main / java / net / ktnx / mobileledger / model / LedgerTransactionAccount.java
index 59e1dab00fb90d69b8d28ec45f465d9574db74a4..c97b7e4a5e7afd801ab73ca4234da776c66753ed 100644 (file)
@@ -19,6 +19,10 @@ package net.ktnx.mobileledger.model;
 
 import androidx.annotation.NonNull;
 
+import net.ktnx.mobileledger.utils.Misc;
+
+import java.util.Locale;
+
 public class LedgerTransactionAccount {
     private String accountName;
     private String shortAccountName;
@@ -31,12 +35,16 @@ public class LedgerTransactionAccount {
         this.setAccountName(accountName);
         this.amount = amount;
         this.amountSet = true;
-        this.currency = currency;
-        this.comment = comment;
+        this.currency = Misc.emptyIsNull(currency);
+        this.comment = Misc.emptyIsNull(comment);
     }
     public LedgerTransactionAccount(String accountName) {
         this.accountName = accountName;
     }
+    public LedgerTransactionAccount(String accountName, String currency) {
+        this.accountName = accountName;
+        this.currency = Misc.emptyIsNull(currency);
+    }
     public LedgerTransactionAccount(LedgerTransactionAccount origin) {
         // copy constructor
         setAccountName(origin.getAccountName());
@@ -67,22 +75,22 @@ public class LedgerTransactionAccount {
 
         return amount;
     }
-
     public void setAmount(float account_amount) {
         this.amount = account_amount;
         this.amountSet = true;
     }
-
     public void resetAmount() {
         this.amountSet = false;
     }
-
     public boolean isAmountSet() {
         return amountSet;
     }
     public String getCurrency() {
         return currency;
     }
+    public void setCurrency(String currency) {
+        this.currency = Misc.emptyIsNull(currency);
+    }
     @NonNull
     public String toString() {
         if (!amountSet)
@@ -93,8 +101,8 @@ public class LedgerTransactionAccount {
             sb.append(currency);
             sb.append(' ');
         }
-        sb.append(String.format("%,1.2f", amount));
+        sb.append(String.format(Locale.US, "%,1.2f", amount));
 
         return sb.toString();
     }
-}
+}
\ No newline at end of file