Objective-c – how to show only two digits after the decimal in float value in iphone

objective cxcode

I have a float number i want that it should display only two digits after decimal like if its is 1.566666 it simply show 1.56

I am using this way for float in my code

    float ProfitForCerenia=costtoclient/markup;

float totalProfit=costtoclient-ProfitForCerenia;

Best Answer

I assume you want a NSString with your number:

[NSString stringWithFormat:@"%.02f", floatVal];