APS Excellence in Physics Education Award
November 2019

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
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 -
Francisco Esquembre
237 Posts

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

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

Paco



OSP Projects:
Open Source Physics - EJS Modeling
Tracker
Physlet Physics
Physlet Quantum Physics
STP Book