C ++:"float"的printf格式规范是什么? ? [英] C++: What is the printf format spec for "float" ?

查看:122
本文介绍了C ++:"float"的printf格式规范是什么? ?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

C ++:"float"的printf()格式规范是什么?

C++: What is the printf() format spec for "float"?

过去,我将%g用作浮点,将%lg用作double.

It used to be that I used %g for float and %lg for double. 

看起来规格已更改,float未定义,double是%g.

It looks like the spec changed and float is undefined and double is %g.

我的内存中有一些要打印的位,所以不能进行强制转换.

I have bits in memory that I am printing out so casting is not an option.

有没有一种方法可以使用printf()打印出float值?

Is there a way that I can print out float values using printf()?

推荐答案

不再有浮点类型的格式规范.打印时,必须将其转换为两倍: http://msdn. microsoft.com/en-us/library/56e442dc.aspx

 

你是什​​么意思?以下应将您的只读float值转换为一个double值,以供打印f.

double temp  =(double)(*(float *)pFloat);




这篇关于C ++:"float"的printf格式规范是什么? ?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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