REAL tag in function - curious transformation

When I put a real tag into my Cicode function the value like 0.127 I see in Debugger Stack Windows 1.226999998 .

What is it ? I tried some real values and got the same result

The trouble is with only tag.

If I put a raw value  0.127 to the CiCode function I see 0.127 in Debugger ...

At the picture below you can see a simple CiCode wich shows the problem is in Citect, not in input pag .....

I noticed it on my input pad ...

  • Hi Anton,
    Thanks for asking this question in the Citect Community. Can you confirm what format setting you have on the tag ("I_L1_FuelTank_Angle")? E.g. is it ##### or ##.##?
    Can you take a look at the Example project, specifically the LOOPS page where the same FormNumPad is used to enter REAL value into the form to set values. Does this experience the same issue?
  • Hello Olivier,

    Why did you asked about the tag format?

    My example of CiCode shows the transformation is in the function variable rValue and untransformation after RealToString() 

  • With tag no troubles - look at the red line .... 1.2270 (format is #.####)

    NumPad shows 1.226999998092 after CiCode ....

  • These are two different things

    Cicode debugger always shows real values with a lot of decimals (full precision).
    Numpad accepts values as a string parameter, so it should inherit the format you supply to it.
  • This is because Citect (and most software) stores floating point values in the IEEE 32-bit floating point number format. It's stored as a number * 10 to a power, which is converted to a decimal value to display it. Unfortunately, some decimal values can't be stored exactly and will be adjusted up or down slightly and you end up with lots of unwanted decimal places. See TN4858. Note that Cicode REAL variables are 64-bit floating point numbers so they have much better precision and you won't see as much rounding as you'll see with PLC variables or other variable tags.

    In your tag definition you should set the tag format. Then you don't have to set it in each graphic object and it should be automatically set when it is passed to the FormNumPad function. For example: 

    tag1 = FormNumpad("Enter value", tag1, 0);

    You should only set it manually in the graphic object if you need to override the default format to display more or less precision in one or two places. If you cannot use the default format from the tag definition, you can override the format in the call to Formnumpad. For example:

    tag1 = FormNumpad("Enter value", RealToStr(tag1, 5, 4), 0);

    or, use the format operator:

    tag1 = FormNumpad("Enter value", tag1:#.####, 0);

  • I can't see TN4858 - I get redirect to https://softwaresupportsp.schneider-electric.com/#/
  • Make sure you log in then try opening the link again.
  • >> Citect (and most software) stores floating point values in the IEEE 32-bit floating point number format

    Maybe you are right but how it looks from the user side: he want to input a value -> original mechanism for it is tool tip - unbelievable - do you know any SCADA with the similar extraordinary input method ? Many people when see Citect Runtime can't guess how to input - if we use touchscreen PC with Citect Runtime the input method wit tool tip is quest - we need use an object like inputPad (sime SCADA have OnScreen keyboard as page property - no forms, no programming, only one checkbox "OnScreen Keyboard") - I made custom InputPad, I try to debug, I set the tag to 1.2270 by init.ci and try to input a new value and what I see - 1.226999998092 instead 1.2270 . I very surprised. It looks like bug....
    Now I use "sInputValue = StrTrim(RealToStr(rInputValue, 20,6));" to get 1.2270 in CiCode ...
  • Yes, the tooltip input method is unusual. However, it is just the simplest input method in Citect. You can use a popup message box with OK/Cancel buttons (Message function), a popup input box (Input function), popup keypad (FormNumpad function), download a customizable alphanumeric keypad from the Aveva website (log in before opening the link), or even make your own custom copy of the FormNumpad function with the buttons you want (which I've seen some people do). You can also do custom things like displaying the default value from one variable and writing the result to another, or writing custom logic to determine whether to accept the user's input. Other SCADA software that has easy checkboxes for input may not give you much or any options to customize the input popup or how the input value is used. That's where Citect gives you an advantage.