使用NSLog方法格式化输出信息
2010-10-25 11:08
375 查看
以下是格式化int,float,double和long型的示例
//
// PrintFormat.h
// DataTypes
//
//
#import <Foundation/Foundation.h>
@interface PrintFormat : NSObject
{
}
-(void) print;
@end
实现部份
//
// PrintFormat.m
// DataTypes
//
//
#import "PrintFormat.h"
@implementation PrintFormat
int num=90;
float _num=90;
double number=700.000;
long mlong=30;
-(void) print{
NSLog(@"The value of integer num is %i", num); //for integer the format specifier is %i
NSLog(@"The value of Long number is %i", mlong); //for Long the format specifier is also %i
NSLog(@"The value of float num is %.2f", _num); //for float the format specifier is %f and we can restrict it to print only two decimal place value by %.2f
NSLog(@"The value of double num is %f", number); //for Double the format specifier is %f (double can be represented in %e ,%E (in this it will be in exponentail form as well as in %e) , %g ,%G )
}
@end
//
// PrintFormat.h
// DataTypes
//
//
#import <Foundation/Foundation.h>
@interface PrintFormat : NSObject
{
}
-(void) print;
@end
实现部份
//
// PrintFormat.m
// DataTypes
//
//
#import "PrintFormat.h"
@implementation PrintFormat
int num=90;
float _num=90;
double number=700.000;
long mlong=30;
-(void) print{
NSLog(@"The value of integer num is %i", num); //for integer the format specifier is %i
NSLog(@"The value of Long number is %i", mlong); //for Long the format specifier is also %i
NSLog(@"The value of float num is %.2f", _num); //for float the format specifier is %f and we can restrict it to print only two decimal place value by %.2f
NSLog(@"The value of double num is %f", number); //for Double the format specifier is %f (double can be represented in %e ,%E (in this it will be in exponentail form as well as in %e) , %g ,%G )
}
@end
相关文章推荐
- 使用文字输出日期格式化方法。
- Dynemic Web Project中使用servlet的 doGet()方法接收来自浏览器客户端发送的add学生信息形成json字符串输出到浏览器并保存到本地磁盘文件
- Linux 程序开发打印 Debug 信息的使用技巧--C语言中几种输出调试信息的方法
- win32使用OutputDebugString输出调试信息的方法
- win32使用OutputDebugString输出调试信息的方法
- Linux 程序开发打印 Debug 信息的使用技巧--C语言中几种输出调试信息的方法
- RtlStringCchPrintfW格式化输出字符串使用方法
- 输出信息log4j.properties的作用与使用方法
- C#使用timer定时在屏幕上输出信息的方法
- java---使用日志输出信息的方法
- 12.iOS格式化日志输出的方法以及在发布状态自动关闭NSLog方法
- 使用python爬取学校门户网站相关信息并格式化输出
- 关于Android 的常用信息输出命令的使用方法的汇总
- java格式化输出 JAVA String.format 方法使用介绍
- C++ cout 格式化输出方法
- php使用for语句输出三角形的方法
- MFC-为子窗体/子窗口的静态控件的特定位置/区域 增加提示/tips信息 使用自绘方法
- keil中使用Astyle格式化你的代码的方法2篇合
- linxu下php使用pdo-dblib连接mssql报错解决方法 错误信息:SQLSTATE[01002]Adaptive Server connection failed (severity 9)
- 使用WebLogic时控制台输出中文乱码解决方法