-1

Using Cycript (mixed with javascript) via a tweak I have this code:

var latitude = [IS2Weather currentLatitude];

This returns -1.65456038607131e+25

I want to limit it to 6 decimal places (-1.654560), what is the correct way to achieve this please? I can't seem to get anything to work.

jscs
  • 63,694
  • 13
  • 151
  • 195
Nicoll
  • 257
  • 1
  • 5
  • 16
  • A latitude value of `-1.65456038607131e+25` seems wrong, also it actually has no decimals. – Teemu Mar 12 '16 at 11:45
  • 1
    -1.65456038607131e+25 expressed without the exponential notation is -16545603860713100000000000. which is clearly an error for a Latitude. See [Engineering notation](https://en.wikipedia.org/wiki/Engineering_notation). – zaph Mar 12 '16 at 12:37
  • Are you complaining about debug output of a meaningless (i.e. erroneous) value? – Eiko Mar 12 '16 at 12:59
  • Yes, sorry, I am in contact with the dev of the tweak to fix the values, thanks for your help. – Nicoll Mar 12 '16 at 13:14

2 Answers2

0

Have you tried calling latitude.toPrecision(6)?

Evan Lucas
  • 622
  • 3
  • 6
  • this gives me -2.63868e+13, I don't know why I get the e or the +. – Nicoll Mar 12 '16 at 11:45
  • That is strange. The e represents exponential notation. See https://en.wikipedia.org/wiki/Scientific_notation (particularly the E notation section) – Evan Lucas Mar 12 '16 at 12:11
  • Thanks for the info, I talking with the dev to get it done in the tweak itself: [NSString stringWithFormat:@"%.8f", currentLocation.coordinate.latitude]; – Nicoll Mar 12 '16 at 12:19
  • @EvanLucas No, the `e` represents engineering notation used in displaying the value. – zaph Mar 12 '16 at 13:26
0

Use javascript .toFixed(n) method

latitude = latitude.toFixed(6);
Munawir
  • 3,346
  • 9
  • 33
  • 51