Fix small display problem when extension starts with 9
authorsrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 30 Sep 2010 15:44:12 +0000 (15:44 +0000)
committersrowen <srowen@59b500cc-1b3d-0410-9834-0bbf25fbcc57>
Thu, 30 Sep 2010 15:44:12 +0000 (15:44 +0000)
git-svn-id: http://zxing.googlecode.com/svn/trunk@1608 59b500cc-1b3d-0410-9834-0bbf25fbcc57

core/src/com/google/zxing/oned/UPCEANExtensionSupport.java

index dea116d..15d15d3 100644 (file)
@@ -160,7 +160,7 @@ final class UPCEANExtensionSupport {
   }
 
   private static String parseExtension5String(String raw) {
-    String currency = null;
+    String currency;
     switch (raw.charAt(0)) {
       case '0':
         currency = "£";
@@ -169,18 +169,28 @@ final class UPCEANExtensionSupport {
         currency = "$";
         break;
       case '9':
-        if ("99991".equals(raw)) {
+        // Reference: http://www.jollytech.com
+        if ("90000".equals(raw)) {
+          // No suggested retail price
+          return null;
+        } else if ("99991".equals(raw)) {
+          // Complementary
           return "0.00";
         } else if ("99990".equals(raw)) {
           return "Used";
         }
+        // Otherwise... unknown currency?
+        currency = "";
         break;
       default:
         currency = "";
         break;
     }
     int rawAmount = Integer.parseInt(raw.substring(1));
-    return currency + (rawAmount / 100) + '.' + (rawAmount % 100);
+    String unitsString = String.valueOf(rawAmount / 100);
+    int hundredths = rawAmount % 100;
+    String hundredthsString = hundredths < 10 ? "0" + hundredths : String.valueOf(hundredths);
+    return currency + unitsString + '.' + hundredthsString;
   }
 
 }