cancel
Showing results for
Did you mean:
cancel
Showing results for
Did you mean:

## Is there a method to convert a string to integer and vice versa?

I'm looping through my array of chapter tags and comparing an attribute value to my loop counter and I don't know if my attribute is a string or integer. Because my document uses a double digit numbering system, attribute value 05 is equal to counter loop value 5. Any way for me to convert 05 to a string so when I compare them, they are not equal?

Also, I'm confused as to why I got an output of 566 when I output 5.00102. See the attached screen shot.

Thank you for all and any help!

Tags (4)
Highlighted

## Re: Is there a method to convert a string to integer and vice versa?

The problem you are having is that ACL fully supports integers, but it doesn't support floating-point numbers. When you use 5.2, ACL doesn't understand that as a floating-point number between 5 and 6. It sees it as "5" + "2", or "52". Remember, the period/decimal is the string concatenation operator in ACL. This explains the unexpected results in your series of comparison tests.

As for 5.00102, ACL sees this as: "5" + "00102", where the latter is interpreted as an octal number; and 102 oct = 66 decimal. Thus, 5.00102 => 566

If you need to compare values such that "05" != 5, then you can force comparison as strings by adding the same (non-numeric) string to both operands, e.g. ("A05" == "A5"). The easiest thing would probably be to write a function for this and use it in your comparisons, something like this:

```function strEqual(a, b) {
return (("A" . a) == ("A" . b));
}```