diff --git a/frontend/cypress/e2e/mainnet/calculator.spec.ts b/frontend/cypress/e2e/mainnet/calculator.spec.ts index 7bcff5cd1..b09dff154 100644 --- a/frontend/cypress/e2e/mainnet/calculator.spec.ts +++ b/frontend/cypress/e2e/mainnet/calculator.spec.ts @@ -94,12 +94,11 @@ describe('Calculator', () => { }); it('updates fiat and sats when entering 1 sat (0.00000001 BTC)', () => { - const expectedFiat = Math.round((MOCK_BTC_PRICE_USD / 100_000_000) * 100) / 100; + const expectedFiat = (MOCK_BTC_PRICE_USD / 100_000_000 * 100 / 100).toFixed(8); cy.get('input[formControlName="bitcoin"]').clear().type('0.00000001'); cy.get('input[formControlName="satoshis"]').invoke('val').should('equal', '1'); cy.get('input[formControlName="fiat"]').invoke('val').then((fiatVal) => { - const fiat = parseFloat(String(fiatVal).replace(/,/g, '')) || 0; - expect(fiat).to.equal(expectedFiat); + expect(String(fiatVal)).to.equal(expectedFiat); }); }); }); diff --git a/frontend/src/app/components/calculator/calculator.component.html b/frontend/src/app/components/calculator/calculator.component.html index e9a8a9537..8c5387b57 100644 --- a/frontend/src/app/components/calculator/calculator.component.html +++ b/frontend/src/app/components/calculator/calculator.component.html @@ -53,7 +53,7 @@
- +
diff --git a/frontend/src/app/components/calculator/calculator.component.ts b/frontend/src/app/components/calculator/calculator.component.ts index 4e3bb6752..d38039d37 100644 --- a/frontend/src/app/components/calculator/calculator.component.ts +++ b/frontend/src/app/components/calculator/calculator.component.ts @@ -186,6 +186,10 @@ export class CalculatorComponent implements OnInit { if (num % 1 === 0) { return Math.round(num); } + // For small values (< 1), show more precision + if (Math.abs(num) < 1 && num !== 0) { + return num.toFixed(8); + } return (Math.round(num * 100) / 100).toFixed(2); } }