문제

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.

도움이 되었습니까?

해결책

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.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top