BruceV 0 Posted June 2 I would appreciate some advice on how to do the following. It seemed trivial, but I quickly got tangled up with the various formats for wide strings, a lot of the Embarcadero information turned out to be for Pascal, I’m working with C++ builder. And there are a number of different wide string formats. I am displaying double values on the canvas, the following obviously works fine: Label1 -> Caption = DoubleVal ; But I got into trouble when I wanted to constrain the display precision, there doesn’t appear to be a setting for the display object and just truncating the field width would be visually unappealing. So I applied the setprecision function with a stringstream output….. ostringstream oss ; oss << setprecision (4) << DoubleVal; // This works How do I go from the stringstream to the GUI? Or is there a more direct approach? Share this post Link to post
oliwe 6 Posted June 3 You could use: Label1->Caption = oss.str().c_str(); 2 Share this post Link to post
Remy Lebeau 1409 Posted June 3 (edited) Alternatively, have a look at Sysutils::Format() Label1->Caption = Format(_D("%0.4f"), ARRAYOFCONST((DoubleVal))); or (Ansi|Unicode)String::sprintf() Label1->Caption = String().sprintf(_D("%0.4f"), DoubleVal); Edited June 3 by Remy Lebeau Share this post Link to post
hansw 4 Posted June 4 You could also use FloatToStrF() which returns a UnicodeString using the local decimal separator. In case you want get a double value from an input text, you could use TryStrToFloat() which returns TRUE if the input is a valid floating point number (which avoids an exception in case the input text is invalid). Share this post Link to post
Remy Lebeau 1409 Posted June 4 7 hours ago, hansw said: You could also use FloatToStrF() which returns a UnicodeString using the local decimal separator. Oh yeah, I keep forgetting about that one. Label1->Caption = FloatToStrF(DoubleVal, ffFixed, 10, 4); There is also FormatFloat(): Label1->Caption = FormatFloat(_D("0.0000"), DoubleVal); Share this post Link to post