Dropping some decimal points on a REAL number

Flicker52

Member
Join Date
Jan 2012
Location
Puyallup, Wa.
Posts
2
I'm utilizing a REAL number on a Controllogix platform, and want to drop some of the decimal points is there a easy way to accomplish this. example number displays 30.170505 I only care about 30.170. I just want to deal with or carry three decimal places.
 
Greetings and welcome to the forum.

Are you asking about this for displaying the number or for a computation?

Most HMIs allow you to configure how many decimal points you want to display. If it is for display then what HMI device are you using?

In RSLogix5000 the software will display as many decimals as is relevant for the number. Your PLC uses 32 bit IEEE-754 floating point format to represent real numbers. This format has a 23 bit mantissa plus one implied bit (24 bits) so the actual float as stored in the PLC memory will have as many decimal places as can be accommodated in the mantissa. Put in plain English, that means the number of decimal places in the number varies according to how large the number is. There is some good information on the IEEE-754 format on wikipedia if you want to dig deeper. We've also discussed it a lot on the forum so you can search for IEEE-754 to find it.

If you are performing a computation then don't worry about how many decimal places there are. No matter what you do you will still have 24 bits in the mantissa. That is just how computers handle real numbers.

One trick that is sometimes used is to multiply a real by 10, 100, or 1000 and make the destination a DINT. Then you set up your display for an implied decimal point and display the DINT value. This will also take care of rounding for you, for example if RealTag = 30.170505 then MUL RealTag 1000 DintTag will put 30171 in DintTag.

This is a pretty generalized answer. We can probably give you a little better answer with more information on what exactly you are trying to accomplish.
 
Last edited:
I'm attemptin a computation as I want to compare a change in the number to see if it stabalizes. I move the number every second to a snapshot number and want to campare the current vs the snapshot, I want to calculate a rate of change so that I can test this rate of change to be within a certain limit. I only care about comparing it to a .000 of an inch I don't care after that
 
Probably the best way to do this is by using the TRN (truncate) instruction inside of a CPT block.

Your instruction would be something like:
CPT Destination_Tag (TRN (Source_Tag * 1000) / 1000)
 
I'm attemptin a computation as I want to compare a change in the number to see if it stabalizes. I move the number every second to a snapshot number and want to campare the current vs the snapshot, I want to calculate a rate of change so that I can test this rate of change to be within a certain limit. I only care about comparing it to a .000 of an inch I don't care after that

If you follow Troy's advice, and MUL by 1000 with Destination: DINT, then DIV that DINT by 1000 with Destination: Real, that will effectively truncate the value past the third decimal point.
 
Why not calculate the rate of change?

I'm attemptin a computation as I want to compare a change in the number to see if it stabalizes. I move the number every second to a snapshot number and want to campare the current vs the snapshot, I want to calculate a rate of change so that I can test this rate of change to be within a certain limit. I only care about comparing it to a .000 of an inch I don't care after that
Then compare rate of change to an upper and lower limit? It sounds like the rate of change is a velocity in your case. What are you really trying to do? My guess is you want some indication that something that moves has stopped.
What is your definition of stopped?
 
+1 for Peter solution - It has advantages

If not use the following

All tags real
Tag1 = Current Value
Tag2 = Last Value

Tag3= Tag1 - Tag2

IF ABS(Tag3) < 0.001 THEN Stopped

---CMP ----------------------------()
ABS((Tag1-Tag2)< 0.001 Stopped

MOV
Tag1
Tag2

 

Similar Topics

Hey guys, I got a carriage that can move with X and Y axe, each side got their own cylinder so left and right. It doesnt happen very often but...
Replies
0
Views
322
Hi all, I'm having a Red Lion DSPLE000 protocol converter on site to interface comms between an Allen Bradley L36ER CompactLogix, a S7-300 PLC...
Replies
0
Views
512
I am almost 100% sure this is related to the issue with the customer losing the 5069-IF8 input module the other day, but alas, it's another...
Replies
0
Views
577
I am using an Allen Bradley CompactLogix 1769-L18ERM-BB1B to control an Allen Bradley 700-H series relay with a 24VDC coil (see pic) The relay is...
Replies
1
Views
888
Our company has recently upgrade to all windows 10 and since this change we have had a problem running RsLogix 500. Everytime we get connected to...
Replies
10
Views
1,956
Back
Top Bottom