How to split and get till 6 digit after the decimal of logitude in javascript? [duplicate]

To get 6 decimals and keep as float, you can use

toFixed

and convert back to number using parseFloat:

parseFloat(number.toFixed(6))

like this

let longs = [151.21484501290186, // I want to store till 151.214845
 77.55814612714227,  // I want to store till 77.558146
 -122.0898574222976 // I want to store till -122.089857
 ]
 
longs =  longs.map(long => parseFloat(long.toFixed(6)))
console.log(longs)


// or just one of them
const long = 151.21484501290186;
const shorter = parseFloat(long.toFixed(6))
console.log(shorter)