From 4c2e177f560908b8231e3ea8d55319b4ef54f6b0 Mon Sep 17 00:00:00 2001 From: K-w-e Date: Sat, 4 Jan 2025 17:21:25 +0100 Subject: [PATCH] Handle transaction lower than 1 --- lib/pages/add_page/add_page.dart | 12 ++++++++++-- 1 file changed, 10 insertions(+), 2 deletions(-) diff --git a/lib/pages/add_page/add_page.dart b/lib/pages/add_page/add_page.dart index a87e4bf..5eed0fc 100644 --- a/lib/pages/add_page/add_page.dart +++ b/lib/pages/add_page/add_page.dart @@ -62,8 +62,16 @@ class _AddPageState extends ConsumerState with Functions { // Remove all non-numeric characters var cleanNumberString = amountController.text.replaceAll(RegExp(r'[^0-9\.]'), ''); - // Remove leading zeros - return cleanNumberString.replaceAll(RegExp(r'^[0\.]+(?=.)'), ''); + // Remove leading zeros only if the number does not start with "0." + if (!cleanNumberString.startsWith('0.')) { + cleanNumberString = cleanNumberString.replaceAll(RegExp(r'^0+(?!\.)'), ''); + } + + if (cleanNumberString.startsWith('.')) { + cleanNumberString = '0$cleanNumberString'; + } + + return cleanNumberString; } void _updateAmount() {