Cancel
Showing results for 
Search instead for 
Did you mean: 

How to ensure that the output coordinates retain 2 decimal places

Experimenter
Experimenter

Now I want to write a locatable object' location to the output window.

 

The program showed as below:

TxTransformation loc = aObject.AbsoluteLocation;
TxMessageBox.Show(loc.Translation.ToString()) ;

 

The output for this program is:

-2671.994, -909.414, 0

 

How can I get the result such as :-2671.99,-909.41,0.00

 

Appreciate for any reply,Thanks !

3 REPLIES

Re: How to ensure that the output coordinates retain 2 decimal places

Experimenter
Experimenter
var vector = loc.Translation;
TxMessageBox.Show(vector.X.ToString("##.00") + ", " +
vector.Y.ToString("##.00") + ", " +
vector.Z.ToString("##.00"));

Re: How to ensure that the output coordinates retain 2 decimal places

Experimenter
Experimenter

Thanks a lot for your reply!

I found that  "ToString("0.00") " is better.

Re: How to ensure that the output coordinates retain 2 decimal places

Siemens Phenom Siemens Phenom
Siemens Phenom

Hi Simona,

 

You can also use ToString(2), TxVector exposes a method string ToString(int precision).

 

Best Regards,

DianaG