输出格式错误 [英] ouput formatting error

查看:176
本文介绍了输出格式错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我得到的输出为:

-2.28463E+001,5.71299E+001,3.14288E+001,4.57282E+001,4.54909E+001



我需要输出为:


I need output as:

-2.28463E+01,5.71299E+01,3.14288E+01,4.57282E+01,4.54909E+01



格式化字符串有问题。


Something is wrong with formating the string.

for (count1=0;count1<Header.num_series;count1++)
{
   fprintf(output_stream,"%.5E",data[count1]);
			
   if(count1!=Header.num_series-1) fprintf(output_stream,",");
}



请帮帮我。

谢谢。


Please help me out.
Thank you.

推荐答案

In似乎在Windows上至少Visual C运行时MSVCRT不提供对输出的指数位数的控制。即使我的相同算法版本目前也无法控制此问题。硬编码为3.



这是我的版本的摘录,它产生与微软相同的输出,但实际上可以读取和调试代码。 :-)



In would appear that on Windows at least the Visual C Runtime MSVCRT doesn't offer control over the number of exponent digits that are output. Even my version of the same algorithm doesn't provide control over this at the moment. It is hard coded to be 3.

This is an extract from my version which produces the same output as Microsoft's but the code can actually be read and debugged. :-)

buffer[ 2 ] = ( exp % 10 ) + '0';
exp = exp / 10;
buffer[ 1 ] = ( exp % 10 ) + '0';
exp = exp / 10;
buffer[ 0 ] = ( exp % 10 ) + '0';
buffer += 3;





我担心你运气不好,除非你想编写自己的自定义 fprintf 我可以从经验告诉你很多工作。



[修改]



看来我已经过时了,MS已经改进了格式化程序的实现。见André的解决方案2。



这很好,因为它之前是垃圾但很糟糕,因为现在它比我的好,这意味着我还有更多的工作要做的事。



I'm afraid you're out of luck unless you want to code your own custom fprintf which I can tell you from experience is a lot of work.

[modified]

It would appear that I'm out of date and MS have improved there formatter implementation. See André's Solution 2.

That's good because it was rubbish before but bad because now it's better than mine which means I have even more work to do.


看起来你可以使用 _set_output_format [ ^ ]功能使用_TWO_DIGIT_EXPONENT作为参数来指定在指数中使用两个数字。



当然如果需要更多数字来表示它们被使用的数字;如链接中的示例所示。
Looks like you can use the _set_output_format[^] function with _TWO_DIGIT_EXPONENT as the parameter to specify that two digits are to be used in the exponent.

Off course if more digit are needed to express the number they are used; as demonstrated in the example from the link.


如果您使用 Windows ,请查看_set_output_format [ ^ ]功能(参见示例代码)。
If you are using Windows, have a look at _set_output_format[^] function (see the sample code).


这篇关于输出格式错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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