开发者

NSNumberFormatter question

I'm trying to save a float like so

[NSNumber numberWithFloat:[dosage floatValue]];

and read the value like so:

dosage = [NSString stringWith开发者_如何学编程Format:@"%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.


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...

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜