0

I'm using an exif reader to extract geo data from a photograph:data.latitude = Number(exif.getTagDescription('GPSLatitude'));I would like the answer to 6 decimal places, so that the output in the console reads 52.629147 instead of 52.62914722222222. Please tell me how to do this?

My question is different to Round to at most 2 decimal places in JavaScript because as a newby this question is not in the context of extracting integers - represented as values - from external media; rather it is just simple numbers.

Community
  • 1
  • 1
edward
  • 55
  • 6
  • 2
    https://developer.mozilla.org/en-US/docs/Web/JavaScript/Reference/Global_Objects/Number/toFixed – Sirko Apr 13 '15 at 15:53

2 Answers2

0

Use toFixed(n)

(10/3)

  • 3.3333333333333335

(10/3).toFixed(4)

  • "3.3333"

This gets you a string, so you may need to convert it back.

Number((10/3).toFixed(4))

  • 3.3333
CPoll
  • 51
  • 1
  • 2
0

I have created the function below for you.

function roundMyNumber(n) {
    return n.toString().indexOf(".") != -1 ? n.toFixed(6) : n;
}

Take a look this Demo: http://jsfiddle.net/9a7oxgek/1/

I hope it's helps.

gon250
  • 3,405
  • 6
  • 44
  • 75