sprintf的:在C双键precision [英] sprintf : double precision in C

查看:113
本文介绍了sprintf的:在C双键precision的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

double a = 0.0000005l;
char aa[50];
sprintf(aa,"%lf",a);
printf("%s",aa);

Output:s0.000000

在上面的code片段中,变量AA只能包含6个小数precision。我想获得一个输出s0.0000005。
能否请你指点我如何实现这一目标?
谢谢

In the above code snippet, the variable aa can contain only 6 decimal precision. I would like to get an output "s0.0000005". Could you please advice me on how to achieve this? Thanks

推荐答案

从你的问题好像你正在使用C99,因为你已经使用%LF 双。

From your question it seems like you are using C99,as you have used %lf for double.

要实现所需的输出替换

sprintf(aa,"%lf",a);

sprintf(aa, "%0.7f", a);

一般语法%A·B表示小数点后用B钮数字。在 A 比较复杂,但是,可读取的>。

The general syntax "%A.B" means to use B digits after decimal point. The meaning of the A is more complicated, but can be read about here.

这篇关于sprintf的:在C双键precision的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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