Repository: Futsch1/medTimer (language: kotlin)

Issue:
Medicine amounts in the thousands are rounded down
**Describe the bug**
When entering a decimal medicine amount in the thousands, the value is usually (but not always) rounded down.

**To Reproduce**
1. Go to the medicine pane
2. Enter a name
3. Go to the newly created medicine
4. Go to the medicine stock page
5. Enter 1000 for the amount
6. Exit the page + medicine
7. Observe that the medicine amount is 1000
8. Reenter the medicine and the stock page
9. Enter 1000.5 for the amount
10. Exit the page + medicine
11. Observe that the medicine amount is 1000, not 1000.5

**Expected behavior**
Decimal medicine amounts to be saved properly

**Screenshots**

https://github.com/user-attachments/assets/71454994-d9a2-4cc7-894c-ab6aeb6f4c22

**Smartphone (please complete the following information):**

- Device: Google Pixel 8a
- Android version: Android 15, GrapheneOS build 2025030900

**Additional context**
When you _do_ manage to get a decimal value placed (e.g. by setting the amount to 100, and then 4487.5 afterwards), simply entering and exiting the stock page will result in a high probability of the value being rounded:

https://github.com/user-attachments/assets/ab7dbd00-7574-4fb2-abc2-3cd51e82b7cf


Discussion hints:
Why is a regex used here?

https://github.com/Futsch1/medTimer/blob/f5ae449597115e0faca19aa8bd452da0b141d2ca/app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt#L95-L105
I don't want to require users to put only the number in the amount, but I want to give a bit more flexibility. So the amount string could look like "2 pills" and it would still work, even "depends, but generally 12.5" would work.

Pull request: Fix medicine amounts in the thousands being rounded down
**Before:**

https://github.com/user-attachments/assets/71454994-d9a2-4cc7-894c-ab6aeb6f4c22

**After:**

https://github.com/user-attachments/assets/c730402d-abbf-432b-974e-f224741ef5a3

Fixes #797

Test command: ./gradlew :app:testDebugUnitTest --tests "com.futsch1.medtimer.MedicineHelperTest"

Fix patch:
diff --git a/app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt b/app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt
index 82665be3a..5f0c53ab0 100644
--- a/app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt
+++ b/app/src/main/java/com/futsch1/medtimer/helpers/MedicineHelper.kt
@@ -93,7 +93,7 @@ object MedicineHelper {
     }
 
     fun parseAmount(amount: String): Double? {
-        val numberRegex = Pattern.compile("\\d+(?:[.,\\s]\\d+)?")
+        val numberRegex = Pattern.compile("\\d+(?:[.,\\s]\\d+)*")
         val matcher = numberRegex.matcher(amount)
 
         return if (matcher.find() && matcher.group(0) != null) {


Test patch:
diff --git a/app/src/test/java/com/futsch1/medtimer/MedicineHelperTest.kt b/app/src/test/java/com/futsch1/medtimer/MedicineHelperTest.kt
index b4bfe9317..1f3863f7c 100644
--- a/app/src/test/java/com/futsch1/medtimer/MedicineHelperTest.kt
+++ b/app/src/test/java/com/futsch1/medtimer/MedicineHelperTest.kt
@@ -26,6 +26,8 @@ class MedicineHelperTest {
         assertEquals(50000.0, MedicineHelper.parseAmount("50000"))
         assertEquals(50000.0, MedicineHelper.parseAmount("50,000"))
         assertEquals(50000.0, MedicineHelper.parseAmount("50 000"))
+        assertEquals(1000.5, MedicineHelper.parseAmount("1,000.5"))
+        assertEquals(1000000.42, MedicineHelper.parseAmount("1 000 000.42"))
         assertEquals(3.566, MedicineHelper.parseAmount("3.566 pills"))
         assertEquals(6.23, MedicineHelper.parseAmount("Take 6.23 pills"))
         assertEquals(6.23, MedicineHelper.parseAmount("Take 6.23 pills at 5 o'clock"))