如何使用目标c在标签中将步进器值显示为1位小数。另外如何将double值舍入到1位小数?

时间:2017-04-22 06:28:28

标签: ios objective-c decimal rounding uistepper

  • 我想在标签中显示 1十进制位置的步进值

  • 我想将double值舍入到1位小数?

这里是我的代码:

- (void)viewDidLoad {

    [super viewDidLoad];

 [_stepperName addTarget:self action:@selector(stepperMethodName) forControlEvents:UIControlEventValueChanged];

}

-(void)stepperMethodName {

    _labelToDisplay.text = [NSString stringWithFormat:@"%f", _stepperName.value];

    NSLog(@"%f", _stepperName.value);
}

三江源。

1 个答案:

答案 0 :(得分:-1)

- (void)viewDidLoad {

    [super viewDidLoad];

 [_stepperName addTarget:self action:@selector(stepperMethodName) forControlEvents:UIControlEventValueChanged];

}

-(void)stepperMethodName {

    _labelToDisplay.text = [NSString stringWithFormat:@"%.1f", _stepperName.value];

    NSLog(@"%.1f", _stepperName.value);
}

//Upto two decimal Places @"%.2f"  

//Upto three decimal Places @"%.3f"