Pregunta

For some reason I'm getting extra numbers on the end when I try to do this:

float lat = floor(1000.0 * origin.latitude) / 1000.0;

result: lat: 37.330002

Even converting the number to an int, and then back to a float, doesn't get rid of the numbers right on the end.

¿Fue útil?

Solución

Try this :

float lat = floorf(1000.0 * origin.latitude) / 1000.0;

In floor() is only for C++, C or Objective C use floorf() and multiplying and dividing by 1000 will give the three decimal point of any number.

Licenciado bajo: CC-BY-SA con atribución
No afiliado a StackOverflow
scroll top