可修改的描述符基类TDes提供了Num(TReal aVal,const TRealFormat& aFormat)方法用来把小数转换成字符串的形式,并可以通过TRealFormat指定格式化的形式,下面的代码展示了几种常用的形式,其它信息可以参考SDK » Developer Library » API Reference » C++ API reference » Character Representation of Real Numbers » Constants:
const TInt KMaxFolatLength = 20;
const TInt KDecimalPos = 3;
TRealFormat format( KMaxFolatLength, KDecimalPos );
format.iType = KRealFormatFixed;
TReal val( 12345.6789 );
TBuf<64> buf;
buf.Num( val, format );
buf中的内容:12,345.679
format.iType = KRealFormatFixed | KDoNotUseTriads;
buf中的内容:12345.679
format.iType = KRealFormatExponent;
buf中的内容:1.235E+04
format.iType = KRealFormatGeneral;
buf中的内容:12345.6789
本文介绍如何使用TDes基类中的Num方法将浮点数转换为不同格式的字符串,包括固定格式、指数格式和通用格式,并展示了不同格式化选项的效果。
356

被折叠的 条评论
为什么被折叠?



