×

Discussion Board

Results 1 to 5 of 5
  1. #1
    Registered User
    Join Date
    Mar 2003
    Location
    Braunschweig
    Posts
    46

    Convert TReal to TBuf with .AppendNum()

    I try to write a real number to a string buffer, just to display it on a listbox.
    On the emulator it leads to the expected result, in my small example 12.34 is shown.
    But on the Nokia E60 phone (S60 3rd edition), there is only the interger part, here 12. The value behind the decimal point is missing.

    My code:

    TBuf16<16> buf;
    _LIT(KListBoxFormat ,"%4.2f");
    buf.Format ( KListBoxFormat, 12.34 );


    Another try, but exactly with the same wrong result on the phone:

    TBuf16<32> str;
    TRealFormat realFormat;
    realFormat.iType=KRealFormatFixed;
    realFormat.iWidth=6;
    str.AppendNum ( 12.34, realFormat);

    Where is the mistake?

  2. #2
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Convert TReal to TBuf with .AppendNum()

    Hi,

    Try with this change:

    TBuf16<32> str;
    TRealFormat realFormat;
    realFormat.iType=KRealFormatFixed;
    realFormat.iWidth=6;
    realFormat.iPlaces=2;
    str.AppendNum ( 12.34, realFormat);

    The number of decimal places is set to 0 by default - seems a bit odd for a real number format but what else is a good default choice?

    Hope that fixes it.

    Sorcery

  3. #3
    Registered User
    Join Date
    Mar 2003
    Location
    Braunschweig
    Posts
    46

    Re: Convert TReal to TBuf with .AppendNum()

    Thanks for your answer, but it doesn't fix the problem.

    I found, it has something to do with the language setting on the phone: when I change to english, everthing works correct, as the emulator do. But on the emulator the result doesn't depends on the selected language.

    When I set the phone to german language, the conversion TReal->TBuf doesn't deliver anything behind the decimal point, it's always 0.

    In Germany the decimal "point" is a comma, and the dot is used to separate the thousand - exactly visa versa as the english notation.

    So I suppose a bug in .Format() and .AppendNum() for some languages?!

  4. #4
    Registered User
    Join Date
    Dec 2006
    Posts
    2,280

    Re: Convert TReal to TBuf with .AppendNum()

    Hi,

    That is an interesting bug. Have you tried overriding the iPoint member manually sot that is doesn't ask the TLocale class for it?

    Sorcery

  5. #5
    Registered User
    Join Date
    Mar 2003
    Location
    Braunschweig
    Posts
    46

    Re: Convert TReal to TBuf with .AppendNum()

    Sorry, it was a heavy bug on my site:

    I use TLex8.Val(aReal) to pharse the real numbers. These numbers are in "english" notation with a decimal point.

    So the problem was not the conversion to TBuf. Both conversion methods are working.

    The fix for the pharse problem is just to take TLex8.Val(aReal, point), where "TChar point" is fixed to the dot. Now the application works independent from the language.

Similar Threads

  1. convert TBuf string to TReal
    By Alicia_S60 in forum Symbian
    Replies: 2
    Last Post: 2004-12-20, 03:39
  2. convert TBuf string to TReal
    By Alicia_S60 in forum Mobile Java General
    Replies: 0
    Last Post: 2004-12-18, 14:00
  3. Convert TBuf String to BlueTooth Address ?
    By valentin_da_itiv in forum Symbian
    Replies: 9
    Last Post: 2003-11-29, 18:45
  4. How to convert TInt32 to TBuf
    By yinjialiang in forum Symbian
    Replies: 1
    Last Post: 2003-09-28, 10:58
  5. How to convert TBuf to char* ?
    By nfx in forum Symbian
    Replies: 1
    Last Post: 2003-02-20, 18:04

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
×