Dec 29, 2009

(Objective-c)How to round a number

Here is a solution to round a float number:

NSString *pi = @"3.14159265";
int floatSize = 3;
NSDecimalNumber *numericValue = [NSDecimalNumber decimalNumberWithString:pi];
NSDecimalNumberHandler *roundingStyle = [NSDecimalNumberHandler 
decimalNumberHandlerWithRoundingMode:
NSRoundBankers scale:floatSize raiseOnExactness:NO raiseOnOverflow:NO 
raiseOnUnderflow:NO 
raiseOnDivideByZero:NO];
NSDecimalNumber *roundedNumber = [numericValue 
decimalNumberByRoundingAccordingToBehavior:
roundingStyle];

or

NSString *pi = @"3.14159265";
NSString *roundedNumber = [[NSString alloc] initWithFormat:
@"%.3f",[pi floatValue]];

Result: 3.142

Dec 7, 2009

(Eclipse)How to resolve "Initializing Java Tooling"

Just met an initialization error on Eclipse, the error message is:

'Initializing Java Tooling' has encountered a problem. An internal error occurred during: "Initializing Java Tooling".

It's really annoying, after googling several sites, here is a working solution:

Delete
the following directory: WORKSPACE_HOME/.metadata/.plugins/org.eclipse.core.resources/.project, and restart Eclipse and problem should be solved.