Do you know how can i convert float value to nsstring value because with my code, there is an error.
My Code :
- (float)percent:(float)a :(float)b{
[NSString stringWithFormat:@"%f", tx_nb_demande_portabilite];
one more option:
NSString * str = [NSNumber numberWithFloat:value].stringValue;
You need to use %f
format specifier for float, not %@
.
NSString *str = [NSString stringWithFormat:@"%f", myFloat];
To use specific number of digits after decimal use %.nf
where n is number of digits after decimal point.
// 3 digits after decimal point
NSString *str = [NSString stringWithFormat:@"%.3f", myFloat];
Obj-C uses C printf
style formatting. Please check printf man page for all other possible formatting.
@"%f"
sounds like more appropriate format string for float
.
A modern (and less verbose) approach would be:
NSString *str = @(myFloat).description;