Reputation: 4409
How to remove decimal if value is equal to 10 else decimal value should not removed.
-(void)viewDidAppear:(BOOL)animated{
[super viewDidAppear:YES];
if (_ratingValue >= 100) {
_ratingValue = 10;
_formatValue = @"%0.0f";
}
else{
_formatValue = @"%.01f";
}
}
_ratingValue == 0.0f ? [cellProductInfo.view_ProductRating setInnerText:@"review"] :
[cellProductInfo.view_ProductRating setInnerText:[NSString stringWithFormat:@" %.01f / 10",_ratingValue]];
If ratingValue is equal 10, I do not want to show the decimal value else if below 10 want to show decimal value.
Upvotes: 0
Views: 43
Reputation: 4409
_ratingValue == 0.0f ? [cellProductInfo.view_ProductRating setInnerText:@"review"] :
[cellProductInfo.view_ProductRating setInnerText:[NSString stringWithFormat:_formatValue,_ratingValue]];
Its works for me!
Upvotes: 0
Reputation: 318834
For 1 decimal place your format needs to be %.1f
. For no decimals you want %.0f
.
If you want values less than 10 to show 1 decimal and values greater or equal to 10 to show none, you want:
if (_ratingValue >= 10.0) {
_formatValue = @"%.0f";
} else {
_formatValue = @"%.1f";
}
Upvotes: 1