精度为double value mfc [英] Precision in double value mfc

查看:145
本文介绍了精度为double value mfc的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

如何将我的double值修改为小数点后的14位数。为了与VB进行cmpare我想修改我的双倍值为14位...在mfc中做...在mfc中怎么办。



在VB双值精度始终为14.但在我们的mfc中它是16.所以我想将值修复为14.



我尝试过:



double d = 2.483650149760682



i想要这些值为2.483650149760

how to fix my double value to 14 digits after decimal point. in order to cmpare with VB i want to fix my double value to 14 digits ..iam doing in mfc.. how to do in mfc.

in VB the double value precision is always 14. but in our mfc its 16. so i want to fix the value to 14.

What I have tried:

double d = 2.483650149760682

i want these value as 2.483650149760

推荐答案

只需在小数点后面打印所需的位数:

Just print them with the required number of digits after the decimal point:
double d = 2.483650149760682;
// Prints as 2.483650149760 (12 digits after decimal point)
printf("%.12f\n", d);



请参阅 printf - C ++参考 [ ^ ]格式选项。要打印到缓冲区(准备字符串),请使用 sprintf - C ++参考 [ ^ ]或使用过的字符串类的格式化方法(如果可用,例如CStringT::Format [ ^ ])。



使用C ++流时使用 setprecision - C ++参考 [ ^ ]方法。


See printf - C++ Reference[^] for the format options. To print to a buffer (prepare string) use sprintf - C++ Reference[^] or a formatting method of the used string class (if available, e.g. CStringT::Format[^] ).

When using C++ streams use the setprecision - C++ Reference[^] method.


您已经在Vb string to double vs mfc cstring to double [ ^ ];请不要重新发布。我还解释了问题所在,并为您提供了解释浮点数的文章的链接。正如我之前所说,如果你真的不明白浮点数你应该避免使用它们。
You already posted this question at Vb string to double vs mfc cstring to double[^]; please do not repost. I also explained what the issue is and gave you a link to an article that explains floating point numbers. As I said then, if you really do not understand floating point you should avoid using them.


这篇关于精度为double value mfc的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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