Author Topic: Basic Label Numeric Formatting  (Read 2755 times)

pal

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Basic Label Numeric Formatting
« on: June 17, 2015, 04:49:08 PM »
I'm a bit embarassed I didn't notice this before . I built a screen last year with a basic label for the date . The data is sent over as part of a double integer array from compact logix . The word contents for today was 17062015 . I've set the numeric format to 00:00:0000 . When the project runs , the display reads 17:06:2016  . I checked the PLC 1st - OK . Added a basic label with no changes and 17062015 displayed . I'm not a VB guru , so I wondered if the formatting is incorrect . For the moment I've added a second basic label without formatting and put it to the back , offset , with just the year showing and shortened the original  label to display the day and month only .

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Label Numeric Formatting
« Reply #1 on: June 17, 2015, 05:38:51 PM »
That one had me scratching my head for a minute. But here is the explanation. Before the number is formatted, it is converted from a string to a single precision float. Floating point numbers in a computer are known for their lack of precision and rounding errors. The number 17062015 after conversion to a Single became 17062016.0

The fix is to use Double precision. Edit AdvancedHMIControls\Controls\BasicLabel.vb, go to line 402, change the code to this:

                    '* 31-MAY-13, 17-JUN-15 Changed from Single to Double to prevent rounding problems
                    Dim v As Double
                    If Double.TryParse(m_Value, v) Then
                        MyBase.Text = m_Prefix & (CDbl(v) * m_ValueScaleFactor).ToString(m_Format) & m_Suffix
                    End If

pal

  • Jr. Member
  • **
  • Posts: 65
    • View Profile
Re: Basic Label Numeric Formatting
« Reply #2 on: June 17, 2015, 05:47:04 PM »
As aways Archie - thanks for the quick response and solution .

Paul

Archie

  • Administrator
  • Hero Member
  • *****
  • Posts: 5322
    • View Profile
    • AdvancedHMI
Re: Basic Label Numeric Formatting
« Reply #3 on: June 17, 2015, 07:08:47 PM »
I appreciate very much the feedback. Every bug fix or feature addition benefits us all.