]> lifelog.hopto.org Git - LifeLog.git/commitdiff
Added substraction in sum for negative numbers.
authorwbudic <redacted>
Wed, 11 Aug 2021 09:05:51 +0000 (19:05 +1000)
committerwbudic <redacted>
Wed, 11 Aug 2021 09:05:51 +0000 (19:05 +1000)
htdocs/cgi-bin/wsrc/main.js

index 2c87725bbb262f7c7e7651f148eabbac158237f4..a9e457ba51f9e6b87327de51a329893964dcf7d8 100644 (file)
@@ -106,7 +106,7 @@ function onBodyLoad(toggle, locale, tz, today, expires, rs_cur, log_limit) {
         e.preventDefault();
         let v = $('#am').val();
         if(v.length==0 || v==0.00){
-            const regex = /^\D*\d+\.*\d*/gm;
+            const regex = /^[\D]?\d+\.*\d*/gm;
             let str = $('#el').val();
             let m; let tot = 0;
 
@@ -115,8 +115,13 @@ function onBodyLoad(toggle, locale, tz, today, expires, rs_cur, log_limit) {
                     regex.lastIndex++;
                 }
                 m.forEach( (match, groupIndex) => {
+                    let v = `${match}`;
+                    let s = v.startsWith('-');
+                    v = v.replace(/^\./g,'0.');
+                    v = v.replace(/^\D/g,'');
                     //console.log(`Found match, group ${groupIndex}: ${match}`);
-                    tot += parseFloat(`${match}`.replace(/^\$/g,''));
+                    if(s){ tot -= parseFloat(v);
+                    }else{ tot += parseFloat(v); }
 
                 });
             }