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.

4

1 に答える 1

0

すでに文字列の場合、y を実装する必要がありますstringWithFormatか?

2 桁の floatvalue の場合、%.2f つまり

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

ハッピーアイコーディング...

于 2010-09-10T04:30:47.633 に答える