Topic
  • 5 replies
  • Latest Post - ‏2013-07-26T22:34:43Z by george.baker
george.baker
george.baker
337 Posts

Pinned topic Usage of $HMLFormatUtil$

‏2013-06-25T22:08:44Z |

I am using HATS v8.5.0.3 and I want to use $HMLFormatUtil$ class to convert strings to numbers, do arithmetic, then convert the result back to a string to insert into a field.  The $HMLFormatUtil$ library has the functions.  However, when I use them they fail.  Let me explain.

I'm running in the US.  I have the following two strings that I want to extract from the screen, add them together,and insert the result into another field.:

  • 2,130.44-
  • 3,536,66

I define two macro variables as follows:

    <vars>
      <create name="$bal_string$" type="string" value=""/>
      <create name="$bal_double$" type="double" value="0.0"/>
    </vars>

I try to perform the following actions:

<extract assigntovar="$bal_string$" continuous="false" ecol="39" erow="11" name="'balance'" planetype="TEXT_PLANE" scol="28" srow="11" unwrap="false"/>
 <varupdate name="$bal_double$" value="$HMLFormatUtil.stringToNumber($bal_string$)$"/>

The extract executes, but the macro blows up on the <varupdate> statement.  If the fields do not contain commas and if the minus sign is in in front it appears that the logic works; however, the presence of If either results in the <update> action failure.

I spotted the following in the Information center:

The methods numberToString() and stringToNumber() perform conversions between a number (that is, a variable or immediate value of type integer or type double, such as 1111.22) and its representation in the current locale (a string, such as '1111.22', '1,111.22', or '1111,22').

As another example, a negative number such as -78 can be represented as:

'-78'
'78-'

The way this is worded implies two things:

  1. The US does not put the minus (-) sign at the end of a number, rather at the front and as such the numeric conversion is invalid
  2. The US does not use commas in representing numbers.

While the first assumption may be true, the second certainly is not.

Am I missing something here?  Where might I find the local rules that this utility is using?

  • george.baker
    george.baker
    337 Posts

    Re: Usage of $HMLFormatUtil$

    ‏2013-06-26T18:28:59Z  

    I've performed other tests and have definitively determined that $HMLFormatUtil.stringToNumber()$  will crash if the string contains leading blanks.  This is inexcusable.  When you extract numeric text from a field the majority of time there will be leading blanks.  To have the macro load the Java String class and trim the string can be done, but it should be built into the method as a default.

    I also found that if you remove the leading blanks the method will run properly with commas.

    It would be most beneficial if the locale rules were documented or at least a link to some other resource where these rules are documented.

  • tmparker
    tmparker
    534 Posts

    Re: Usage of $HMLFormatUtil$

    ‏2013-06-27T20:38:32Z  

    I've performed other tests and have definitively determined that $HMLFormatUtil.stringToNumber()$  will crash if the string contains leading blanks.  This is inexcusable.  When you extract numeric text from a field the majority of time there will be leading blanks.  To have the macro load the Java String class and trim the string can be done, but it should be built into the method as a default.

    I also found that if you remove the leading blanks the method will run properly with commas.

    It would be most beneficial if the locale rules were documented or at least a link to some other resource where these rules are documented.

    Hi George,

    I agree with your viewpoint.  If I had written the code I would certainly have trimmed the value to prevent errors.  I don't have the code in front of me so I'm not sure what was done but it sounds like the trim is missing.  However, this is HOD code so we would have to open the issue for HOD to fix.  I'll try to forward this thread to the HOD team to see if they have anything to add about this.

    As for the rules for the locale, I assume that is the generic locale rules such as some countries use decimals and some use commas, etc...  That should be found on the web somewhere.  I am pretty sure we don't do anything specific in our code other that call the methods that take into account the locale of the system.

    Thanks

    Tim

  • george.baker
    george.baker
    337 Posts

    Re: Usage of $HMLFormatUtil$

    ‏2013-06-27T21:16:46Z  

    I am opening a PMR against HATS for this issue.  I assume that HATS will move this internally to HOD for resolution.  

  • tmparker
    tmparker
    534 Posts

    Re: Usage of $HMLFormatUtil$

    ‏2013-06-28T05:07:19Z  

    I am opening a PMR against HATS for this issue.  I assume that HATS will move this internally to HOD for resolution.  

    Sure, even if it's in the HOD code we would need the PMR to pull in the new HOD version into HATS. I sent an email to the HOD team as well to let them look at this thread.

    Thanks

    Tim

  • george.baker
    george.baker
    337 Posts

    Re: Usage of $HMLFormatUtil$

    ‏2013-07-26T22:34:43Z  
    • tmparker
    • ‏2013-06-28T05:07:19Z

    Sure, even if it's in the HOD code we would need the PMR to pull in the new HOD version into HATS. I sent an email to the HOD team as well to let them look at this thread.

    Thanks

    Tim

    A PMR was opened and the defect acknowledged.  I have tested a fix and it resolves the problem.  I cannot say when the fix will be generally available.