Skip to main content

WEBfactory 2010

Precision rounding for buttons and toggle buttons

Abstract

Check out this article and learn how to use double values and precision rounding for buttons and toggle buttons.

Description

When using double values in buttons and toggle buttons, Silverlight processes the value without preserving the full precision of the double. The reason for this is the native code being used in the XAML parser:

"When a Double value is processed from Silverlight XAML as a XAML attribute value, the value does not preserve the full precision that is implied by the definition of Double in code and the runtime. This is due to native code being used as part of the Silverlight XAML parser operations, and deliberate optimization for numeric values that are applicable to a user interface."

Source: Double Structure

EXAMPLE: If value 1 of a button is 88,88 and value 2 is 99,99, at runtime, when the button is pressed and the value is checked either with Test Center or a WFTextDisplay1, the value 1 will be 88,87XXXXXXXXXXX and value 2 will be 99,98XXXXXXXXXXXX.

This can be tested by using a WFToggleButton4 control (with value 1 88,88 and value 2 99,99 and the Setpoint1 signal) and two output controls: WFNumericDisplay1_2 (which will display the real values) and the WFTextDisplay1 (which will display the poorly rounded values).

WF_SE_664.jpg
Solution

The solution adopted by WEBfactory 2010 on this matter is to round the double to 5 digits. This fix will affect the next controls:

  • WFButton1

  • WFExtendedButton

  • WFStatesButton1

  • WFStatesToggleButton1

  • WFToggleButton1-4

If more accurate precision is needed, the Factor X1, Factor X2, Factor Y1 and Factory Y2 can be configured for the desired signal, in WEBfactory 2010 Sudio.

WF_SE_665.jpg