打印在C用printf常量指数值 [英] Print constant exponent value using printf in c
问题描述
我用%E
格式说明。试图%3.2E
或%4.3E
。
I used %e
format specifier. Tried %3.2e
or %4.3e
.
例如:结果
如果 VAR = 0.001342
,那么我想打印 0.1342e-02
。但是版画 1.342e-03
结果
如果 VAR = 0.543124
,那么我想打印 54.3124e-02
。但是版画 5.43124e-01
结果
如果 VAR = 0.0123653
,那么我想打印 1.23653e-02
。
Example:
if var=0.001342
, then I want to print 0.1342e-02
. But prints 1.342e-03
if var=0.543124
, then I want to print 54.3124e-02
. But prints 5.43124e-01
if var=0.0123653
, then I want to print 1.23653e-02
.
这是什么都可能的价值,我只想解决我的指数值的打印结果。
That is what ever maybe the value, I just want to fix my exponent value an print the result.
推荐答案
这本手册:
EE 双参数圆润,并在风格转换
[ - ] + d.ddde -dd哪里有小数点前有一位
字符和数字的数以后它等于precision;如果precision丢失,它被当作6;如果
precision是零,没有出现小数点字符。一个E转换使用字母 E'(而不是
E')介绍
指数。该指数总是包含至少两个数字;如果
值为零,指数是00。
eE The double argument is rounded and converted in the style [-]d.ddde+-dd where there is one digit before the decimal-point character and the number of digits after it is equal to the precision; if the precision is missing, it is taken as 6; if the precision is zero, no decimal-point character appears. An E conversion uses the letter
E' (rather than
e') to introduce the exponent. The exponent always contains at least two digits; if the value is zero, the exponent is 00.
EE
为科学记数法,所以在只有一个非NUL位小数点。
eE
is for the scientific notation, so only one non nul digit before the decimal point.
您需要自己进行转换,如:
You need to make the conversion by yourself, like:
float number = 0.01023;
float normalized = number*100;
int mantissa_int_part = normalized;
int mantissa_decimal_part = (normalized-mantissa_int_part)*10000;
printf("%02d.%04d e-2",mantissa_int_part,mantissa_decimal_part);
这篇关于打印在C用printf常量指数值的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!