In this section we will see the correct example of NSLog function that prints the float value.
In this section we will see the correct example of NSLog function that prints the float value.The following code example of NSLog function prints the value of float variable. You can use the technique discussed here in your iPhone application to test and debug the code.
Here is the code example of NSLog function that prints the value of float.
//
// PrintFloat.h
// DataTypes
//
//
#import <Foundation/Foundation.h>
@interface PrintFloat : NSObject
{
float _float;
}
-(void) print;
-(void) set_float: (float) n;
@end
The class implementation code is as follows:
//
// PrintFloat.m
// DataTypes
//
#import "PrintFloat.h"
@implementation PrintFloat
-(void) set_float: (float) n
{
_float = n;
}
-(void) print {
NSLog(@"float value is: %f", _float);
}
@end
The %f is used here in the above example.