diff --git a/CHANGELOG.md b/CHANGELOG.md index 7a4a3bc176..6f95c9cdfe 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -13,6 +13,10 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0 - Removed the deprecated `auth` endpoint of the login with _Security Token_ (`GET`) - Simplified the `getHistorical()` function response in the data provider interface +### Fixed + +- Fixed the parsing of negative numbers in `extractNumberFromString()` (used by the manual data provider) which incorrectly dropped the minus sign + ## 3.29.0 - 2026-07-18 ### Added diff --git a/libs/common/src/lib/helper.spec.ts b/libs/common/src/lib/helper.spec.ts index 6a6fe47734..abac8acd57 100644 --- a/libs/common/src/lib/helper.spec.ts +++ b/libs/common/src/lib/helper.spec.ts @@ -43,6 +43,22 @@ describe('Helper', () => { ).toEqual(999.99); }); + it('Get negative decimal number', () => { + expect(extractNumberFromString({ value: '-999.99' })).toEqual(-999.99); + }); + + it('Get negative decimal number (with currency)', () => { + expect(extractNumberFromString({ value: '-999.99 CHF' })).toEqual( + -999.99 + ); + }); + + it('Get negative decimal number with group (comma notation)', () => { + expect( + extractNumberFromString({ locale: 'de-DE', value: '-99.999,99' }) + ).toEqual(-99999.99); + }); + it('Not a number', () => { expect(extractNumberFromString({ value: 'X' })).toEqual(NaN); }); diff --git a/libs/common/src/lib/helper.ts b/libs/common/src/lib/helper.ts index 9a32927e23..30b0c2a680 100644 --- a/libs/common/src/lib/helper.ts +++ b/libs/common/src/lib/helper.ts @@ -210,8 +210,9 @@ export function extractNumberFromString({ value: string; }): number | undefined { try { - // Remove non-numeric characters (excluding international formatting characters) - const numericValue = value.replace(/[^\d.,'’\s]/g, ''); + // Remove non-numeric characters (excluding international formatting + // characters and the minus sign to preserve negative values) + const numericValue = value.replace(/[^\d.,'’\s-]/g, ''); const parser = new NumberParser(locale);