在输入为4567.123456的程序中,输出为4567.123535 [英] In my program when input is 4567.123456 then output is 4567.123535

查看:101
本文介绍了在输入为4567.123456的程序中,输出为4567.123535的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

#include<stdio.h>
#include<conio.h>

void main()
{
    float n;
    printf("Enter a number");
    scanf("%f", &n);
    printf("Number is....: %f", n);
    getch()
}

推荐答案

浮动指针数字表示为基数的因子和指数二。这意味着它们在范围和精度之间进行权衡。某些数字,如您所显示的数字,无法以该格式准确表示,但只能达到一定数量的有效数字。在你的情况下是6位数,这是C浮点变量的通常数字。



参见:

http://en.wikipedia.org/wiki/Floating_point [ ^ ]
Floating pointer numbers are represented as a factor and and exponent to the base two. This means that they are kind of a trade-off between range and precision. Some numbers, as the one you showed, cannot be represented in that format exactly, but only up to a certain numbers of significant digits. In your case that's 6 digits, which is the usual number for C float variables.

See also:
http://en.wikipedia.org/wiki/Floating_point[^]


参见 http://docs.oracle.com/cd/E19957-01/806-3568/ncg_goldberg.html [ ^ ]。


试试double

Try with double
double n;
printf("Enter a number");
scanf("%lf",&n);
printf("Number is....: %lf",n);



这可能会解决您的问题


This might solve your problem


这篇关于在输入为4567.123456的程序中,输出为4567.123535的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆