I am trying to use a custom property to display a Decimal(5,2) column from a Mysql5.6 table.
I originally set it to Type: Float but the result is 305.1199996 instead of 305.12
I tried all the existing Types (ver.7.94) and I either get 305 or 305.1199996
Again, the table column’s type is Decimal(5,2) and below is my custom
I just attempted the following Expression and received this Error msg - Syntax Error on Token:‘COMMA’(Line 1, Char 104). I made some tries at modifying th esyntax but kept getting other mistake errors.
round((try({Root Container.PM Power Table.data}[{Root Container.PM Power Table.selectedRow}, 6], 100.1), 2)
To expand a little bit: Ignition doesn’t/can’t use precise decimal types when returning data from databases, for complex reasons, so the value is coerced into a 32-bit or 64-bit IEEE754 floating point number, which does not have arbitrary precision; so 305.11999996is the “exact” representation Java has for the number. Rounding on output is the ‘correct’ way to present that information; or, if you don’t need to do any actual math with it, you can also cast in your query as a string, which will allow the DB to preserve the precision information on the DECIMAL column.
Also, you had an extra open parentheses in your expression. Try:
round(
try(
{Root Container.PM Power Table.data}[{Root Container.PM Power Table.selectedRow}, 6]
, 100.1
)
, 2
)
You just want to put the round around the expression, not the try:
round({Root Container.PM Power Table.data}[{Root Container.PM Power Table.selectedRow}, 6], 2)