我是 javascript 新手,正在尝试使用经度坐标。
我有 3 个经度,我想将它们分割并存储到小数点后 6 位
我一次只能执行其中一项,这不好,因为这些数字可以从用户输入动态获得。
例如:
let long1 = 151.21484501290186; // I want to store till 151.214845
let long2 = 77.55814612714227; // I want to store till 77.558146
let long3 = -122.0898574222976; // I want to store till -122.089857
// this method only works if starting value is of 2 digits but failed when it's 3
const result = long2.toString().substr(long2.toString().indexOf('.') - 2, 9);
console.log(result) // 77.558146
Run Code Online (Sandbox Code Playgroud)
请帮我。