Integer to Real

ozzye

Member
Join Date
Oct 2012
Location
Michigan
Posts
14
Have a device sending me 2 integers one is the value and the other is the divisor. Would there be a compact way to divide this value not have to convert it to 10ths and display it as a real?

Thank you
 
What PLC?
What Display?

Did you mean that one integer contains the whole number and the other contains the fraction after the decimal point?

Or is it returning a 32 bit IEEE float as two 16 bit integers?
 
Last edited:
So if source a 12345(value/integer) and source b is 2(divisor/integer) I would think the destination would equal 123.45(real). Getting a zero in the real.
 
Based on what you said, it looks like Source B is giving you how many points are after the decimal.

Divide 12345 by 102.

CPT DESTINATION_tag SOURCEA_tag/(10**SOURCEB_TAG)

If destination is a DINT you'll get the unrounded result 123 in this case. If destination is a REAL you'll get 123.45.
 
Always dividing by 100, how could the divisor determine this?

Destination: GAUGE_PROFILES.PROFILE1_REAL

Expression: GAUGE_PROFILES.PROFILE1_MEASURED_VALUE / (100 ** GAUGE_PROFILES.PROFILE1_DIVISOR)
 
You are not always dividing by 100.

You are dividing by 10N where N is the number in the second integer.

So if N = 0 then 10N= 1 and you get 12345
If N = 1 then 10N = 10 and you get 1234.5
if N=2 then 10N = 100 and you get 123.45
If N=3 then 10N = 1000 and you get 12.345
and so on.

If that isn't what you need then please supply more detailed information about what you are doing. I want to help you with the solution but I am still guessing about what it is you really want with the limited details you have provided so far.
 
Last edited:
Ok, got it, typed in a 100 for 10**.

Destination: Real_Value_Tag

Expression: Int_Value_Tag / (10 ** Int_Divisor_Tag)

Thank you
 
Anytime you're dividing with a dynamic denominator, you should put a compare before the compute to ensure that it's greater than zero. If you don't you could end up with a processor fault that may be hard to find.
 
That is good advice. Its always good to trap for divide by zero whenever it is possible that it might happen.

In this case we are OK with skipping a divide by 0 trap since the divisor is always 10 raised to some power. There is no power to which ten can be raised that will equal zero. Put another way, Log100 is undefined.
 

Similar Topics

Good morning all, I'm integerating a device with a Rockwell PLC with V34 Studio 5000. The device reports error codes using a single integer to...
Replies
19
Views
1,299
Hi all, I've got a bit of a need to convert an integer (and a real in another situation) to a string with a particular format. This seems possible...
Replies
11
Views
2,452
Hello, Could somebody give for me advice how to seperate real number to integer Entered from Mitsubishi HMI GS Series to Mitsubishi PLC FX-1n...
Replies
2
Views
2,566
Hi everyone :* I am using using unity pro v.13 i want to do the mathematical function of floor() which makes for example 1.2 to 1 and makes 2.9...
Replies
7
Views
3,106
DearAll, I have a problem in coverting 48bit integer to Real.Kindly see the details as below System:- compactlogix L43 With MVI69-MCM...
Replies
1
Views
1,703
Back
Top Bottom