1
こんにちは私は、アプリケーションのようにユーザーによって入力された10進数をフォーマットする必要があります。フォーマットNSNumberFormatterを使用して10進数を入力してください
100. = 100
90.00 = 90
90.1 = 90.1
90.22 = 90.22
90.227 = 90.23
どのようにNSNumberFormatterを使用してこれを達成する必要がありますか?
私は、コードをconsizeする必要がある他の条件
if ([cell.textField.text rangeOfString:@"."].location != NSNotFound)
{
NSString *strAfterDecimal = [cell.textField.text componentsSeparatedByString:@"."].lastObject;
NSInteger count = [strAfterDecimal length];
if(count == 0)
{
customField.value = [cell.textField.text
stringByReplacingOccurrencesOfString:@"." withString:@""];
}
else if(count == 1 || count == 2)
{
if([strAfterDecimal integerValue] > 0)
{
customField.value = cell.textField.text;
}
else
{
customField.value = [cell.textField.text componentsSeparatedByString:@"."].firstObject;
}
}
else if(count > 2)
{
if([strAfterDecimal integerValue] > 0)
{
customField.value = [NSString stringWithFormat:@"%0.2f",[cell.textField.text floatValue]];
}
else
{
customField.value = [cell.textField.text componentsSeparatedByString:@"."].firstObject;
}
}
}
場合、私は、このカスタムを使用して同じことを達成しました。クライアントによると、私はリンゴによって与えられたデフォルトの機能は、物事
これは、次の要件を解決しますか?「90.00 = 90」? – sketchyTech
@sketchyTechはいそれは – vadian
ありがとうalot @vadian。それは私の日を救った。それは私の要求に従って動作します。再度、感謝します。 :) –