//单元测试通过/***四舍五入并保留N位小数**@paramnumber数值字符串*@paramafterPoint第几位小数**@return处理后结果*/+(NSString*)halfUpDecimalNumber:(NSString*)numberafterPoint:(int)position{/*Mode的枚举类型NSRoundPlain,//四舍五入NSRoundDown,//只舍不入NSRoundUp,//不舍只入NSRoundBankers//*/if([numberlength]==0){return@"";}NSDecimalNumber*ouncesDecimal=[NSDecimalNumberdecimalNumberWithString:number];NSString*formatStr=@"0.";for(inti=0;i<position;i++){formatStr=[formatStrstringByAppendingString:@"0"];}NSNumberFormatter*doubleValueWithMaxTwoDecimalPlaces=[[NSNumberFormatteralloc]init];[doubleValueWithMaxTwoDecimalPlacessetNumberStyle:NSNumberFormatterDecimalStyle];[doubleValueWithMaxTwoDecimalPlacessetPaddingCharacter:@""];[doubleValueWithMaxTwoDecimalPlacessetPaddingPosition:NSNumberFormatterPadAfterSuffix];[doubleValueWithMaxTwoDecimalPlacessetFormatWidth:position];[doubleValueWithMaxTwoDecimalPlacessetPerMillSymbol:@""];[doubleValueWithMaxTwoDecimalPlacessetAlwaysShowsDecimalSeparator:YES];[doubleValueWithMaxTwoDecimalPlacessetGroupingSeparator:@""];[doubleValueWithMaxTwoDecimalPlacessetRoundingMode:NSNumberFormatterRoundHalfUp];[doubleValueWithMaxTwoDecimalPlacessetPositiveFormat:formatStr];return[doubleValueWithMaxTwoDecimalPlacesstringFromNumber:ouncesDecimal];}