Convert decimal to float

I would like to know how to convert a value in decimal, that comes from opc (this means for example decimal 3, in boolean 00000000 00000011) to float format cause it's really a real (or float) value.


Show us the details of how this value comes in (most drivers will interpret as floating point for you if you tell them to).

In the origin (a CNC machine control) it's a REAL value (or float).
Later, this values is got by a Siemens gateway through mqtt (as picture attached) to publish it as opc ua.

In Siemens gateway, it's defined this value as float (as shown in picture, yellow marks) but gateway iterprets this value as decimal, instead of a float. (I think this is a bug of Siemens. I'll let them know)

As a result, I'm trying to change this type of value (decimal to float) in Ingnition, which is susbcribed to this Siemens gateway where the value is. And that's the reason why I need to convert from decimal to float, or maybe decimal-boolean-float, I don't know.

Thanks in advance,

It may need to be done via scripting, using Float.intBitsToFloat

>>> from java.lang import Float
>>> Float.intBitsToFloat(1125515264)

Hi Kevin!

I'm trying it but it doesn't work. The truth is this is the first time I import resources into code ("Float"). Could you tell me what I`m doing wrong?

The tag "MemoryGH2055_maq" has a script as shown for writing its value in "MemoryGH2055" but as float.

Thanks in advance.

Looks like a missing indent on line 2. Look in the right margin of the code editor for little red marks at syntax errors.

Hi both!

Pturmel, you're right and I had already fixed the mistake, but also I had to define origin value as INTEGER and final value as FLOAT.

And now yes, it works!

Thanks so much!!

1 Like