Round to at most 2 decimal places In JavaScript

πŸ‘¨πŸ½β€πŸ’» Round to at most 2 decimal places In JavaScript

Table of Contents

UseΒ Math.round(num * 100) / 100

Edit:Β to ensure things like 1.005 round correctly, we use

Math.round((num + Number.EPSILON) * 100) / 100

Leave a Comment

Your email address will not be published. Required fields are marked *

No data found.