Board index » cppbuilder » TextOut - how to format a double?

TextOut - how to format a double?


2008-05-22 02:03:57 AM
cppbuilder75
I declared:
double d;
Later I wish to write that value to the Canvas:
Form1->Canvas->TextOut(x, y, d);
However, instead of the values showing as:
23.47364957847, etc.
I want to print them to one or two decimal places:
23.47, or
23.4
How can I format TextOut()?
I would use the Help feature in my old BCB 6, but so far the
engineers can't seem to get it properly registered.
Thanks,
Nick
 
 

Re:TextOut - how to format a double?

"Nick Gessler" < XXXX@XXXXX.COM >wrote in message
Quote
How can I format TextOut()?
You have to format the double separately, ie:
Form1->Canvas->TextOut(x, y, FormatFloat("0.00", d));
Or:
Form1->Canvas->TextOut(x, y, AnsiString().sprintf("0.2lf", d));
Gambit
 

Re:TextOut - how to format a double?

Quote
How can I format TextOut()?

I would use the Help feature in my old BCB 6, but so far the
engineers can't seem to get it properly registered.

Thanks,
Nick


Your thinking is incorrect!!
Do not format TextOut
Instead, first format the number into a text variable, then text out
that variable.
 

{smallsort}