iphone – 字符串加倍
发布时间:2020-12-14 17:18:30 所属栏目:百科 来源:网络整理
导读:我希望你能帮我解决这个“小问题”.我想将一个字符串转换为double / float. NSString *stringValue = @"1235";priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue doubleValue]/(double)100.00]; 我希望这可以将价格标准设置为12,35,但我得到
我希望你能帮我解决这个“小问题”.我想将一个字符串转换为double / float.
NSString *stringValue = @"1235"; priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue doubleValue]/(double)100.00]; 我希望这可以将价格标准设置为12,35,但我得到一些奇怪的长字符串对我来说没有任何意义. 我试过了: priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue intValue]/(double)100.00]; priceLabel.text = [NSString stringWithFormat:@"%d",[stringValue doubleValue]/100]; 但都没有成功. 解决方法
您必须使用%f来显示浮点/双精度值.
然后%.2f表示点后2位数 NSString *stringValue = @"1235"; NSString *str = [NSString stringWithFormat:@"%.2f",[stringValue doubleValue]/(double)100.00]; NSLog(@"str : %@ nn",s); priceLabel.text = str; OUTPUT: str:12.35 (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |