Limiting Decimal positions

Isaacx

Member
Join Date
May 2010
Location
Pen Argyl
Posts
22
Hey guys...quick question. I have a ML1400 communicating with an HMI designed in VB.NET that controls a test sequence. My problem is that the user only wants to see the position meter displaying values with two decimal places (19.34, 0.43, etc...) The meter is reading from a float register (F11:10), but often, the number in F11:10 will have so many decimal places that the meter will not hold everything. For example:

F11:10 = 6.382947282091

Then, the meter will try to show everything, but due to size constraints, only ......2947282......... is displayed (which is essentially useless to the user).

Is there a way that I can limit the number of decimal places that the Float registers display? Or is there another way to get around this issue?

Thanks,
Dave
 
I bet the
function in vb.net will work.
In excel it is =LEFT(A3,4)
I don't know the vb.net syntax, but I am interested in your solution so please post the answer once you get it.
Good luck​
 
I got it. It was much easier to format in VB...I was missing the "fixed" format. Here is the chunk of code...

Private Sub ReadTimer_Tick(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ReadTimer.Tick

Dim oldvalues As String
Dim oldvalues2 As String
CurrentPosition.Read()
oldvalues = CurrentPosition.Values(0).ToString()
CurrentPositionValue.Text = Format(oldvalues, "Fixed")
RelativePosition.Read()
oldvalues2 = RelativePosition.Values(0).ToString()
RelativePositionBox.Text = Format(oldvalues2, "Fixed")

Just out of curiosity, is there a way to do this same procedure within RSLogix?
 
There isn't a practical way to limit the display resolution of a float within RSLogix because of the way a float is stored in computer memory. It doesn't matter how many decimal places a float has, it is always stored in the same format. When a float is displayed for viewing it is converted to a string and the string is displayed. The conversion software takes care of the display resolution then. The actual float value in computer memory doesn't change.

To compound matters, many values cannot be represented exactly as a float. 10.2 for example cannot be represented, it become 10.199999999999999 and the computer cannot get any closer. Display subroutines have sophisticated algorithms to take care of rounding and truncation of the displayed string so that you get 10.2.
 
Last edited:
Multiply your Float by 100 and store the result in an Integer, that will limit your answer to 2 decimal points, you then need to be able to set the position of the decimal point though, nothing comes for free.
 

Similar Topics

Hi all, I'm looking at an application with a Powerflex 755 with encoder feedback, being run as a standard VSD (as opposed to a motion axis), with...
Replies
5
Views
1,734
Has someone tried MC_TorqueLimiting along with MC_GearIn , on a Siemens S120 axis , controlled by an S7-1500T plc ? If we limit the torque ...
Replies
7
Views
1,592
I have two 24VDC motors that draw a little under 10A nominal, but the in-rush is over 20A. They are driven with a 20A power supply but on initial...
Replies
6
Views
1,658
We have tasked with developing a crowd/backing gate for a dairy where cows need to be gently pushed from waiting area into the milking parlor...
Replies
20
Views
6,721
I have an application that requires control of the pressure in a pumped line but with flow rate limiting. The pump is inverter-controlled and the...
Replies
9
Views
2,961
Back
Top Bottom