Strip floating point number apart for compare

Tim Ganz

Member
Join Date
Dec 2010
Location
Dallas, Texas
Posts
674
What is a good method to take a floating point number and strip off the numbers to the right of the decimal so they can be use in a compare instruction?

Moving the floating point number to an integer address should strip off the numbers to the right of the decimal and leave me with the whole number to compare but i also need to be able to compare the numbers to the right of the decimal separate also.
 
Truncate (trunc) is the function that removes decimals.

Decimal := Real - trunc(Real);
 
Last edited:
he wants the decimal (fractional) portion. Truncate removes the fractional portion leaving the integer

Seriously?

Decimal := Real_Val - trunc(Real_Val);

This doesn't work??

I've even tested it. Real_Val = 10.53 gives Decimal = 0.53

trunc.PNG
 
Last edited:
I need glasses, didnt look at the whole string, got stuck on the Trunc instruction. You're right.

MOD is a single command with the same result so either way works.
 
I need glasses, didnt look at the whole string, got stuck on the Trunc instruction. You're right.

MOD is a single command with the same result so either way works.

The reason why I would like to give a different solution is that the modulo (mod) function doesn't handle real (floating point) in all systems. Some systems only allows int and dint (and alike) for mod.

He didn't state what system he uses.
 
Do you want -10.53 to return:
0.53
0.47
-0.53
-0.47?

It would be nice to handle a negative number just for future reference but in this instance its setup so that the number i am working with can never be negative.

The result i am trying to get and put out to the HMI is for example 69.8125 would be 5 feet 9 13/16s inches.

38.1875 would be 3 feet 2 3/16 inches and so on.
 

Similar Topics

No trivial trains and tunnels this time! This is an actual problem that was solved about 20 years ago by one of our engineers. The goal is to...
Replies
25
Views
6,090
Hello Experts; Good day. I have strip chart OPC version 1.4.1.6. I have RSLOGIX version 13 to 309Studio 5000). I have RSLINK LITE version 4.0...
Replies
0
Views
1,227
Hi, Just wondering what everyone uses for terminal strip labels? We have an old Roland DXY-1150 plotter with ACS (Murrplastik) software that...
Replies
8
Views
2,109
Dears I have cold roll coil and need to control it after rewinding using any analog sensor to detect edge position and then send its signal to...
Replies
2
Views
1,222
Does anyone make a brush on insulation to put on the exposed end of a terminal strip jumper bar that has been cut down to size? Although these...
Replies
14
Views
5,150
Back
Top Bottom