]> git.ipfire.org Git - thirdparty/paperless-ngx.git/commitdiff
Fix: Dont parse numbers with exponent as integer (#5457)
authorshamoon <4887959+shamoon@users.noreply.github.com>
Fri, 19 Jan 2024 14:29:13 +0000 (06:29 -0800)
committerGitHub <noreply@github.com>
Fri, 19 Jan 2024 14:29:13 +0000 (06:29 -0800)
src-ui/src/app/components/common/input/number/number.component.spec.ts
src-ui/src/app/components/common/input/number/number.component.ts

index 889aa219838f3139ccd6a6905c3c2c4c33e2c7c1..9024614bb631a5fff8baa42330d5aa88ba43a00d 100644 (file)
@@ -60,4 +60,9 @@ describe('NumberComponent', () => {
     component.writeValue(11.1)
     expect(component.value).toEqual(11.1)
   })
+
+  it('should support scientific notation', () => {
+    component.writeValue(1.23456789e8)
+    expect(component.value).toEqual(123456789)
+  })
 })
index 0b113a4de847bd42dc482c2ef214fff6c8fa35dd..6675e44981a502bb7e534fbd2c6e8f4f7674717b 100644 (file)
@@ -37,7 +37,8 @@ export class NumberComponent extends AbstractInputComponent<number> {
   }
 
   writeValue(newValue: any): void {
-    if (this.step === 1) newValue = parseInt(newValue, 10)
+    if (this.step === 1 && newValue?.toString().indexOf('e') === -1)
+      newValue = parseInt(newValue, 10)
     if (this.step === 0.01) newValue = parseFloat(newValue).toFixed(2)
     super.writeValue(newValue)
   }