格式编号为百分比

Fil*_*lou 3 cocoa-touch objective-c

我写了这段代码,我想将数字z格式化为百分比.

float l = ([textField2.text floatValue]);
float g = ([textField1.text floatValue]);

float x = l/1.23;
float y = x-g;
float z = y/l;

label.text = [[NSString alloc] initWithFormat:@"%2.2f \%",z]; 
Run Code Online (Sandbox Code Playgroud)

Ila*_*ian 6

使您的代码如下.

label.text = [[NSString alloc] initWithFormat:@"%2.2f %%",(z*100)]; 
Run Code Online (Sandbox Code Playgroud)