Thread: Displaying a double using DrawString()

  1. #1
    george7378
    Guest

    Displaying a double using DrawString()

    Hi everyone,

    I'm working on a program in which I want to display a reading (in the form of a double) in a window using GDI+. I am able to use the DrawString method to display a given WCHAR, but I can't work out how to display a double. I know I will probably have to convert it to a WCHAR, but again, I'm lost.

    Can anyone help me out on this at all? Failing that, is there another GDI+ function I can use to display doubles on the screen?

    Thanks.

  2. #2
    Bored Programmer
    Join Date
    Jul 2009
    Location
    Tomball, TX
    Posts
    428
    Virtual reality hello world http://www.rodneybrothers.com/vr/vrh...rld/index.html in html and javascript.
    Viewable with dodocase, google cardboard, OR, and other compatible VR gear.

  3. #3
    george7378
    Guest
    DrawString requires (for some stupid reason) that you convert to a WCHAR before you can display the output. I can't find anything on how to convert a double to a WCHAR...

  4. #4
    Registered User
    Join Date
    Jun 2011
    Posts
    4,513
    I haven't dabbled much in wide characters, but have you looked into perhaps using "swprintf()" to print the value to a wide-character string?

  5. #5
    george7378
    Guest
    Thanks for the reply - that seems to be the right way to go, but now I can't figure out how to use swprintf()! If anyone who knows about this kind of thing could give me or direct me to an example bit of code on how to convert a double to a wchar_t, then it would be a big help

  6. #6
    george7378
    Guest
    After a lot more trying, I came up with this method that works:

    Code:
    double d = 1.23
    std::wstringstream a;
    a << d;
    std::wstring result = a.str();
    graphics.DrawString(result.c_str(), -1, &font, PointF(x,y), &brush);

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Replies: 11
    Last Post: 04-15-2012, 07:10 PM
  2. Replies: 3
    Last Post: 04-05-2008, 07:44 AM
  3. Replace double with long double in all my code.
    By boyfarrell in forum C Programming
    Replies: 8
    Last Post: 04-30-2007, 04:17 PM
  4. Changing double time to double cost
    By chrismax2 in forum C++ Programming
    Replies: 2
    Last Post: 04-24-2004, 10:29 AM
  5. the diffrence between static double and double
    By sayeem81 in forum C Programming
    Replies: 6
    Last Post: 02-18-2002, 12:12 PM