Numeric text Field with a Float

I have a recipe screen where the ingredients have to equal 100, my problem is that the values can have three decimal places so the tags have to be a Float.

When I type in 13.675 into a text box the Float value is 13.674653425300002303023 etc…

Normally this wouldn’t be an issue but since I have to have exactly 100 no more or less this is throwing off all of my calculations.

I tried reading the double value but that one also gives me the same output (ie… 13.6746534253 )

I tried using an expression and the round function but that didn’t work either.

I’m at a loss on what to try, I know I could build some scripting to take care of it but before i put a few hours into it i wanted to check and see if anyone else had similar issues and what they did to fix it.

Thanks

I just tried it out typing 13.675 into a numeric textbox and printing out the doubleValue (13.675)
Ignition 7.7 RC1

I’m using 7.6.4, I haven’t tried 7.7 yet

Try changing the “Number Type” property to “Double” and then re-enter your value. I’m using 7.5.1 and it works for using as long as the number type is set to double.

I changed the Number Type as you suggested and I have the same result.

I am using a system.tag.write to set a memory tag to a value. Say 12.375

The memory tag is then binded to a numeric text field for display and editing.

once the tag is written to, the display is 12.375 but if you look at the properties, the float value is 12.374000980034000, the double value is 12.375, just what i want

if i read the value from the double, bam, it now reads 12.374000980034000

If i type into the text field and enter 12.375, both the double will list 12.375 while the float reads 12.374000980034000.

It is perplexing…

With this issue the only place we need to make sure the value is written correctly is to the PLC. What you are going to need to do is edit the tags Metadata settings for the Format String to this #,##0.000 this should force the value to stay in the numeric range you are wanting.

Thanks James,

With the Metadata set and the type set to float 8 i still get the same values. I tried setting the number type to double and that also had no effect. so i figured out a python way to get around it but i think its a little clunky… This is driving me nuts!

value = 12.12500567899999
works = round(Decimal(str(value)), 3)

where are you checking the value on the tag ?

Hi James,

When a button is clicked to load the values, i check the values entered on the Numeric Text Fields (NTF). The NTF is tied to a float8 memory tag, the values the tag are loaded either from a database or manually entered.

When loaded from a DB, the values add the extra decimal places, manually entered it works.

Call when you are free and we can do a gotomeeting

This is more of a DB issue than an Ignition issue. DECIMAL data type is better for storing precise number values. Float and Real are known as approximate data types

MySQL is similar.

yes, the values are stored as decimal(6,3) in the database.

The problem is that for tags, my only option is floating point… as I have listed above.

When my value of 12.765 is loaded from the db, the floating point tag adds 12.765000234100

I’m wondering if the error is being introduced by the Java database driver?

From what i was reading online, it looks like its the way Java does floats.

Do we have any update in this issue…It is driving me crazy…As i control the format to 00.00 then i convert to string and after i use left(,)… :frowning:

No, its the way computers do floats. You’ll need to learn how to use integers as fixed-place decimals. Use integer PLC registers where the values are thousandths of what you are using now. Scale to include a decimal point for display and for DB operations only.

1 Like