문자열을 double 값으로 변환하여 주석의 좌표로 사용하려고합니다.좌표의 두 자리 소수점
지도에 소수점 이하 5 자리를 표시하려면 double 값이 필요합니다.
문자열이 hello
이고 필요한 double이 whatsup
이라고 가정 해 봅시다.
문자열의 형식은 정확히 내가 원하는 방식이고 이중으로 만들고 싶습니다. 그래서 문자열의 doublevalue 속성을 사용합니다. 이 여분의 제로와 더블 있습니다
coordinate.latitude = whatsup
:
NSString *hello = @"12.61655";
double whatsup = hello.doubleValue;
NSLog(@"%f",whatsup); //this gives 12.616550 WITH A ZERO in the end
NSLog(@"%.5f",whatsup); //This gives me the correct value of 12.61655 with only 5 decimal places
그래서 지금 내가 쓰고 싶은 경우.
어떻게
5 소수 자릿수가 두 배입니다coordinate.latitude = SOMETHING HERE
을 쓸 수 있습니까?
어떻게 든 "% .5f"를 구현할 수 있습니까?
numberformatter를 시도했지만 나에게 NSnumber를 제공합니다. double이 필요합니다 :
이 코드를 for 루프에 사용하여 주석 (핀)을 그립니다.
복식으로 동일한 forloop을 사용할 때 잘 동작합니다.
double latitudeFromCSV = [[components objectAtIndex:0] doubleValue];
double longitudeFromCSV = [[components objectAtIndex:1] doubleValue];
CLLocationCoordinate2D annotationCoord;
annotationCoord.latitude = latitudeFromCSV;
annotationCoord.longitude = longitudeFromCSV;
NSLog (@ "coordinate.latitude = % .5f", whatsup); ' – Till
오 기다리십시오. 앞에 0이없는 이중 값을 저장하고 싶지는 않습니까? –
그래, 마지막에 0이 아닌 double 값을 저장하고 싶습니다 ... 단지 5 개의 소수만 저장하십시오. 그게 가능하니? –