开发者

Formatting float values

开发者 https://www.devze.com 2023-04-08 04:42 出处:网络
This is probably a stupid question but anyway. 开发者_如何学JAVA I wan the number I set on my label to be formated nicely like this 20,000,000 .

This is probably a stupid question but anyway.

开发者_如何学JAVA

I wan the number I set on my label to be formated nicely like this 20,000,000 . How do I do this ?

For now I've set the number of decimal points to 0 so I just get the whole number without any places.

[NSString stringWithFormat:@"%.0f", slider.value];


you can use the following formatter:

-(void)setCurrencyFormat
{

    NSNumberFormatter *CurrencyFormat = [[NSNumberFormatter alloc] init];  
    [CurrencyFormat setNumberStyle:NSNumberFormatterCurrencyStyle];

    label.text= [CurrencyFormat stringFromNumber:[NSNumber numberWithDouble:billAmountInDouble]];

    NSString *st1=[NSString stringWithFormat:@"%@",[CurrencyFormat stringFromNumber:[NSNumber numberWithDouble:individualTaxInDouble]]];
    label.text=st1;


}


Check out the docs for NSNumberFormatter - you can do pretty much everything with that.

0

精彩评论

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

关注公众号