Education Prize Logo
Science SPORE Prize
November 2011

NSF Logo
The Open Source Physics Project is supported by NSF DUE-0442581.

Number formatting in 2D Text Drawable post and replies

Return to the Number formatting in 2D Text Drawable thread
Login to post to this thread

Number formatting in 2D text drawable - Aug 14 at 10:43AM
Tze Ko
1 Posts

I've created a 2D text drawable inside a plotting panel.
This field is intended to move around following the moving object.
I want to display the velocity of the object using this 2D text drawable so I typed "v="+v in the text field.
The prompt and value of v were displayed but the problem is it automatically gives the full decimal of v, such as giving v=2.1354816846815 which moves around the plotting area.

There is no format field in the properties for 2D text drawable. How can I format the value of v to be displayed in 2 decimal places?

Post edited August 14, 2014 at 10:43 AM EST.

Post edited August 14, 2014 at 10:47 AM EST.


Replies to Number formatting in 2D text drawable

Re: Number formatting in 2D text drawable - Aug 15 12:31AM
Francisco Esquembre
138 Posts

Use this:
"v="+ _view.format(v,"0.00");

This will print the value of v with exactly 2 decimal points.

Paco



The OSP Network:
Open Source Physics - Tracker - EJS Modeling
Physlet Physics
Physlet Quantum Physics