程序清单3.7_showf_pt.c程序_《C Primer Plus》P49

// showf_pt.cpp : 定义控制台应用程序的入口点。
//
/* showf_pt.c -- 以两种方式显示浮点值 */

/*
    时间:2018年06月06日 21:10:25
    代码:程序清单3.7_showf_pt.c程序_《C Primer Plus》P49
    目的:printf("%e") 以指数记数法来显示浮点数字
*/
#include "stdafx.h"


int _tmain(int argc, _TCHAR* argv[])
{
    float aboat = 32000.0;
    double abet = 2.14e9;
    long double dip = 5.32e-5;
    printf("%f can be written %e\n", aboat, aboat);
    printf("%f can be written %e\n", abet, abet);
    printf("%f can be written %e\n", dip, dip);
    getchar();

    return 0;
}

/*
    在VS2010中运行结果:
--------------------------------------------------
32000.000000 can be written 3.200000e+004
2140000000.000000 can be written 2.140000e+009
0.000053 can be written 5.320000e-005
--------------------------------------------------
    google翻译如下:

32000.000000 可以写成 3.200000e+004
2140000000.000000 可以写成 2.140000e+009
0.000053 可以写成 5.320000e-005
--------------------------------------------------
    总结:
        %e(打印指数记数法的数字)
        e4(表示小数点往右移动4位)
        e-5(表示小数点往左移动5位)
--------------------------------------------------

*/


猜你喜欢

转载自blog.51cto.com/13555061/2125710
今日推荐