Class myphysicslab.lab.controls.NumericControlBase

Provided By
All Implemented Interfaces
All Known Direct Subclasses

A user interface control for displaying and editing the numeric value of an object. Has optional upper and lower limits on the allowed value. Has control over the number of decimal places shown, see #setDecimalPlaces and maybe significant digits also?

Because this is an Observer, you can connect it to a Subject; when the Subject broadcasts events, this will update the value it displays.

This is the base class for myphysicslab.lab.controls.NumericControl which which connects to a myphysicslab.lab.util.ParameterNumber.

Number Formatting

To format the number, we currently never use exponential notation, instead we display the number without any thousands separators, with some number of fractional decimal places depending on the 'mode'. There are two modes for how NumericControlBase formats the number and calculates the size of the text field:

  • Variable decimal places mode: ensures that the requested number of significant digits are visible by changing how many fractional decimal places are shown, based on the magnitude of the value.

  • Fixed decimal places mode: fixes the number of fractional decimal places to show, regardless of the size of the value.

The displayed value is rounded to a certain number of digits, and therefore the displayed value can differ from the target value. NumericControlBase allows for this difference by only making changes to the target value when the the user modifies the displayed value, or when #setValue is called.

Upper and Lower Limits

The value displayed should always match the target (rounded according to number of digits), even when that value is outside the upper or lower limits. The limits only affect attempts by to change the value, by #setValue or by the user changing the number displayed in the control.

To Do List

There is a problem with the current variable mode which is when you have a very tiny number, say 1.234567e-12, then it will format it like: 0.000000000001234567 when setting the significant digits to 7 and decimals to be variable. This is usually far bigger than we want. It should instead either switch to exponential, or have a maximum limit on the number of decimals shown.

new NumericControlBase( label, getter, setter, textField )


the text shown in a label next to the number input field

getterfunction(): number

function that returns the current target value

setterfunction(number): ?

function to change the target value


the text field to use; if not provided, then a text field is created.

Instance Methods

Instance Properties