Share on Google+Share on Google+

NSLog float example code

Advertisement
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.

 

Advertisements

Posted on: July 29, 2009 If you enjoyed this post then why not add us on Google+? Add us to your Circles

Share this Tutorial Follow us on Twitter, or add us on Facebook or Google Plus to keep you updated with the recent trends of Java and other open source platforms.