×
Namespaces

Variants
Actions

如何将浮点数转换为描述符

From Nokia Developer Wiki
Jump to: navigation, search
Article Metadata

文章
翻译:
hoolee
最后由 hamishwillee 在 22 Dec 2011 编辑


描述符类有2个方法可以将浮点数转换为描述符。TDesC16::Num()和TDesC16::AppendNum()方法。大多数人在使用TDesC16:Num(TInt64 aVal)方法做浮点转换时会犯一些错误。因为因为没有TDesC16::Num(TReal aVal)这样的函数,需要的是 TDesC16::Num(TInt64 aVal)。因此我们必须传递2个参数,一个实数和一个实数的格式化参数(TRealFormat)

//Define TRealFormat to use it in conversion.
TRealFormat realFormat;
//type of format, use KDoNotUseTriads if u do not want to allow tried character
realFormat.iType = KRealFormatFixed || KDoNotUseTriads;
//width your number
realFormat.iWidth = 30;
//number of character after decimal point
realFormat.iPlaces = 2;
//number of character on left of decimal point to place tried character.
realFormat.iTriLen = 15;
 
TReal64 realNumber;
TBuf<25> buffer;
realNumber = 123.456;
buffer.Num(realNumber,realFormat); // it gives 123.45
buffer.Zero();
buffer.AppendNum(realNumber,realFormat); // it gives 123.45
This page was last modified on 22 December 2011, at 07:46.
74 page views in the last 30 days.
×