Rounding Issue

I have a numeric text field formatted as float. It’s related tag is the float4 datatype. When I type in a float value in the numeric text field, such as 3.253 the tag and numeric text field get updated with the value of 3.000 in the tag browser. I can’t find anything to fix this rounding issue. I’ve adjusted the decimal format in the properties, but doesn’t help. Any help would be appreciated.

For the numeric text field, make sure you have the following properties:

Number Type: Float
Value (Float): Bind to the float4 tag
Decimal Format: #,##0.###

Thank you! :smiley:

I also have similar type of problem. My tag “setspeed” from PLC via KEP is integer type. There is numeric box with DB tag “DB_setspeed” float type. when I enter value in numeric box and clicks the “transfer” button, my script multiplies the DB tag value by 100 and sends to PLC. This is working fine.
Now I want to change the color of numeric box if the PLC tag (divided by 100) is not equal to DB tag. This is to prompt the operator that he changed the value but forget to transfer to PLC. But actually what is happening, suppose DB value is 0.35, then in the script when I divide PLC tag by 100, it becomes 0.34999999 and logic of color change does not work properly. (I tried to change the format, tried by reversing the logic (DB value multiply by 100 and then compare etc.) but I could not get the consistent result. I have 8-10 such different numeric boxes with various DB and PLC tags. Some places it works but some places it does not

Hi sdahigaonkar,

What you are experiencing is a common problem… floating point binary simply doesn’t exactly represent decimal fractions, making equals comparisons unreliable. This is true in every programming language that uses binary float.

The best practice in Ignition is to bind your float SQLtag directly to the PLC integer, with a 100:1 numeric scale. Do not even have a SQLtag with the unscaled integer. Then all of your displays will consistently show the correct value, and writes to the float value will be automatically scaled to the appropriate integer write.

If your application absolutely must have a data entry field with a separate “send” script, use a one-way binding on a pop-up screen to fill that field. The script then just writes the current value back to the same tag before closing the pop-up. Or abandons any new value if the operator cancels the pop-up.