Decimals

Watch the explanation for this recipe in the video Check The Element Contains A Number That Ends With Two Decimalsopen in new window.

Two decimals

Let's confirm the element has text that ends with two decimal numbers.

<div id="amount">1,465.30</div>
cy.contains('#amount', /\.\d\d$/)

Optional zero last decimal

Sometimes the last digit is optional, if it is zero.

<div id="amount">1,465.3</div>
cy.contains('#amount', /\.\d\d?$/)

Tip: In Cypress v12 you can get the text of the element and invoke the regular expression match method, see cypress-mapopen in new window