"intAmount"를 10 진수 또는 정수 (즉, 사람이 .10 또는 1을 입력 할 수 있음)로 만들려면 아래 코드를 변경해야합니다. 마지막 줄 "myProduct"는 정수가 아닌 십진수 여야하며 예를 들어 "18.00"형식으로 제품을 반환해야합니다. 다른 사람이 누군가 내 코드 스 니핏을 변경하도록 도울 수 있습니까?NSString을 10 진수로 변환
//amt has to be converted into a decimal value its a NSString now
NSInteger intAmount = [amt intValue];
//where total gets updated in the code with some whole (integer) value
NSInteger total=0;
//Change myProduct to a decimal with presicion of 2 (i.e. 12.65)
NSInteger myProduct=total*intAmount;
본 텍스트 필드에서 올바른 분수를 얻을 수
NSDecimalNumber intAmount = [amt doubleValue];
//Keep in mind totalCost is an NSInteger
NSDecimalNumber total=totalCost*intAmount;
'10 진수'는 '비 정수'또는 '소수'를 의미하지 않습니다. 십진수는 기본입니다. –
십진수는 또한 클래스입니다 ... 적어도 C#에서는 fl, oat 또는 double보다 좋습니다. 나는'total'과'intInteger'를 "십진수"로 유지할 것입니다. 그러나 할당 전에 바로 캐스트를 수행하십시오. 그런 다음 문자열을 "십진수"로 변환하는 방법을 찾아야합니다. 당신을 위해 워크 플로우를 단순화 하겠지만. http://forums.macrumors.com/showthread.php?t=900938 –
@Hamish Grubijan :이 질문은 분명히 코코아/Objective-C에 관한 것이므로 "소수"와 같은 클래스는 없습니다. – Chuck