# Numeric text Field with a Float

**URL:** <https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904>\
**Category:** Ignition\
**Created:** [August 14, 2014, 4:57pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904 "2014-08-14T16:57:38Z")\
**Posts on this page:** 15\
**Page:** 1

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 14, 2014, 4:57pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/1 "2014-08-14T16:57:38Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![jpark](https://avatars.discourse-cdn.com/v4/letter/j/a88e57/32.png) [@jpark](https://forum.inductiveautomation.com/u/jpark)\
**Post date:** [August 14, 2014, 5:19pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/2 "2014-08-14T17:19:34Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 14, 2014, 5:39pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/3 "2014-08-14T17:39:43Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![JGJohnson](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/jgjohnson/32/29582_2.png) [@JGJohnson](https://forum.inductiveautomation.com/u/JGJohnson)\
**Post date:** [August 14, 2014, 6:15pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/4 "2014-08-14T18:15:28Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 14, 2014, 7:35pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/5 "2014-08-14T19:35:11Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![james.hunt](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@james.hunt](https://forum.inductiveautomation.com/u/james.hunt)\
**Post date:** [August 14, 2014, 9:33pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/6 "2014-08-14T21:33:34Z")

</div>

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.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 14, 2014, 10:48pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/7 "2014-08-14T22:48:27Z")

</div>

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)

---

<div class="post-metadata">

**Author:** ![james.hunt](https://avatars.discourse-cdn.com/v4/letter/j/fbc32d/32.png) [@james.hunt](https://forum.inductiveautomation.com/u/james.hunt)\
**Post date:** [August 15, 2014, 4:26pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/8 "2014-08-15T16:26:49Z")

</div>

where are you checking the value on the tag ?

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 18, 2014, 1:10pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/9 "2014-08-18T13:10:07Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![adamaustin](https://avatars.discourse-cdn.com/v4/letter/a/5f8ce5/32.png) [@adamaustin](https://forum.inductiveautomation.com/u/adamaustin)\
**Post date:** [August 21, 2014, 1:36pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/10 "2014-08-21T13:36:32Z")

</div>

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](http://technet.microsoft.com/en-us/library/ms187912(v=sql.105).aspx)

> [@](#):
>
> The float and real data types are known as approximate data types. The behavior of float and real follows the IEEE 754 specification on approximate numeric data types.
> 
> Approximate numeric data types do not store the exact values specified for many numbers; they store an extremely close approximation of the value. For many applications, the tiny difference between the specified value and the stored approximation is not noticeable. At times, though, the difference becomes noticeable. Because of the approximate nature of the float and real data types, do not use these data types when exact numeric behavior is required, such as in financial applications, in operations involving rounding, or in equality checks. Instead, use the integer, decimal, money, or smallmoney data types.

[MySQL](http://code.rohitink.com/2013/06/12/mysql-integer-float-decimal-data-types-differences/) is similar.

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 21, 2014, 2:55pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/11 "2014-08-21T14:55:59Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![Pat](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@Pat](https://forum.inductiveautomation.com/u/Pat)\
**Post date:** [August 21, 2014, 8:01pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/12 "2014-08-21T20:01:47Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![drewdin](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/drewdin/32/3363_2.png) [@drewdin](https://forum.inductiveautomation.com/u/drewdin)\
**Post date:** [August 21, 2014, 8:53pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/13 "2014-08-21T20:53:25Z")

</div>

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

---

<div class="post-metadata">

**Author:** ![ganainy.ahmed](https://avatars.discourse-cdn.com/v4/letter/g/c67d28/32.png) [@ganainy.ahmed](https://forum.inductiveautomation.com/u/ganainy.ahmed)\
**Post date:** [October 28, 2017, 9:03pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/14 "2017-10-28T21:03:43Z")

</div>

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(,)… ☹

---

<div class="post-metadata">

**Author:** ![pturmel](https://sea1.discourse-cdn.com/inductiveautomation/user_avatar/forum.inductiveautomation.com/pturmel/32/3295_2.png) [@pturmel](https://forum.inductiveautomation.com/u/pturmel)\
**Post date:** [October 28, 2017, 11:28pm UTC](https://forum.inductiveautomation.com/t/numeric-text-field-with-a-float/8904/15 "2017-10-28T23:28:27Z")

</div>

> [@drewdin](#):
>
> From what i was reading online, it looks like its the way Java does floats.

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.
