0

I want to store an Array like this

const price = [ 1.000, 24.500, 3.99, 4.00 ];

but when i'm print this with console.log, the 1.000 becomes 1 , the 4.00 become 4.

how to keep the thousand number with dot separator?

Nsgt
  • 76
  • 6

1 Answers1

1

Try the following code:

console.log(price.toFixed(3));

edit-1:


prices.forEach((price)=>{ console.log(price.toFixed(3)); })

let truePrice = prices.map( (price)=> price.toFixed(3) )

oreopot
  • 3,392
  • 2
  • 19
  • 28
  • it works, thanks. `let truePrice = prices.forEach((price)=>{ console.log(price.toFixed(3)); })` – Nsgt Jun 02 '20 at 04:59