Categories
JavaScript

Number

  1. Handle with Price: 2 decimal places
  2. Ref

Handle with Price: 2 decimal places

let number = 6.1234
number.toFixed(2) // '6.12' -> string

// Convert to number type
// Method 1
parseFloat(number2.toFixed(2)) // 6.12 -> number
// Method 2
+number2.toFixed(2) // 6.12

Ref

https://stackoverflow.com/questions/3163070/javascript-displaying-a-float-to-2-decimal-places

Leave a comment