views:

35

answers:

1

I'm trying to save a float like so

[NSNumber numberWithFloat:[dosage floatValue]];

and read the value like so:

dosage = [NSString stringWithFormat:@"%1.0f", [prop.dosage floatValue]];

The Problem is that numbers like 0.11 end up being 0

I've read that I can use NSNumberFormatter, but the docs are not very clear on how to set it for rounding.

A: 

if its already a string then y do you need to implement stringWithFormat?

for 2 digits floatvalue use %.2f i.e.

dosage = [NSString stringWithFormat:@"%0.2f", [prop.dosage floatValue]];

HAPPY iCODING...

Suriya