[vtkusers] Set decimal digits in vtkVariant

Xiaopeng Yang yxp233 at postech.ac.kr
Tue Jan 25 20:03:34 EST 2011


Thank you Jeff. It works for me.

 

Yang

 

From: Jeff Baumes [mailto:jeff.baumes at kitware.com] 
Sent: Wednesday, January 26, 2011 3:21 AM
To: Xiaopeng Yang
Subject: Re: [vtkusers] Set decimal digits in vtkVariant

 

I'm saying you don't use vtkVariant at all and refactor your code to
something like:

 

std::ostringstream oss;

oss.precision(8); // Whatever you'd like

oss << "Resected volume = " << vol2/1000;

std::string message = oss.str();

 

Jeff

 

On Tue, Jan 25, 2011 at 1:12 PM, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:

So you mean before my code of showing message, I can apply ostringstream to
set the decimal digits of vol2/1000. Am I right? 

 

From: Jeff Baumes [mailto:jeff.baumes at kitware.com] 
Sent: Wednesday, January 26, 2011 1:18 AM
To: Xiaopeng Yang
Cc: vtk
Subject: Re: [vtkusers] Set decimal digits in vtkVariant

 

On Tue, Jan 25, 2011 at 9:15 AM, Xiaopeng Yang <yxp233 at postech.ac.kr> wrote:

Greetings!

 

May I ask how to set decimal digits in vtkVariant? For example, I would like
to set one decimal digit for the double type variable: vol2/1000. 

 

Here is part of my code:

 

std::string message = "Resected volume = ";

message += vtkVariant( vol2/1000 ).ToString();

 

There is currently no way of doing this with vtkVariant. The conversions use
the default settings of STL ostringstream and there is currently no API to
change them. The string conversions are meant to produce something
reasonable for presentation (e.g. for displaying in a UI text box), but not
for anything rigorous like serialization. You should go through a more
standard technique (e.g. ostringstream) to accomplish this.

 

Jeff

 




-- 
Jeff Baumes, Ph.D.
Technical Lead, Kitware Inc.
(518) 881-4932

-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://www.vtk.org/pipermail/vtkusers/attachments/20110126/25039ff4/attachment.htm>


More information about the vtkusers mailing list