Unit tests are rounded by/** * and reserved with n decimal places * * @param number Numeric string * @param afterPoint number of decimals * * @return processed results */+ (nsstring *) Halfupdecimalnumber: (nsstring *) Number afterpoint: (int) position{ Enumeration type of /* mode nsroundplain, // Rounding NSRoundDown, // only nsroundup, // not only enter NSRoundBankers // */ if ([number length]==0) { return @ ""; } nsdecimalnumber *ouncesdecimal = [nsdecimalnumber decimalnumberwithstring:number]; nsstring *[email protected] "0."; for (int i=0; i<position; i++) { formatstr=[formatstr stringbyappendingstring:@ "0"]; } NSNumberFormatter *doubleValueWithMaxTwoDecimalPlaces = [[NSNumberFormatter Alloc] init]; [doublevaluewithmaxtwodecimalplaces setnumberstyle: nsnumberformatterdecimalstyle]; [doublevaluewithmaxtwodecimalplaces setpaddingcharacter:@ ""]; [doublevaluewithmaxtwodecimalplaces setpaddingposition: nsnumberformatterpadaftersuffix]; [doublevaluewithmaxtwodecimalplaces setformatwidth:position]; [doublevaluewithmaxtwodecimalplaces setpermillsymbol:@ "" ]; [doublevaluewithmaxtwodecimalplaces setalwaysshowsdecimalseparator:yes]; [doublevaluewithmaxtwodecimalplaces setgroupingseparator:@ ""]; [doublevaluewithmaxtwodecimalplaces setroundingmode: nsnumberformatterroundhalfup]; [doublevaluewithmaxtwodecimalplaces Setpositiveformat:formatstr]; return [doublevaluewithmaxtwodecimalplaces stringfromnumber:ouncesdecimal];}
Comprehensive online all kinds of unreliable algorithms, write their own rounding method