float,double 小数点有效数字

#include "stdafx.h"
#include <Windows.h>

int main()
{
    float  f = 3.1234567890123456789012345678901234567890;
    double d = 3.1234567890123456789012345678901234567890;
    printf("1/3 = %.20lf\n", 1.0 / 3.0);//0.33333333333333331482961625624739099293947219848633
    printf("f = %f %lf %.20lf\n", f,f,f);
    printf("d = %f %lf %.20lf\n", d,d,d);

    //OutputDebugString输出,和printf一样的结果
    char buf[255] = { 0 };
    sprintf_s(buf, "f=%.20lf d=%.20lf\n", f, d);
    OutputDebugString(buf);
//  float是6 - 7位
//  double是15 - 16位
    getchar();
    return 0;
}
/*
1/3 = 0.33333333333333331483 //16个3说明double 16位有效数字
f = 3.123457 3.123457 3.12345671653747558594 //float:6位有效数字,四舍五入
d = 3.123457 3.123457 3.12345678901234569125 //double:16位有效数字
*/

float是6-7位
double是15-16位

  • 3
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值