var aText = 'Here is the number: %%number%%';
var aNumber = 1;
var aResult = utils.stringReplace(aText, '%%number%%', aNumber);
// aResult = "Here is the number: 1.0"
var anotherResult = 'Here is the number: ' + aNumber;
// anotherResult = "Here is the number: 1"
If I “cast” the number myself by doing
var aResult = utils.stringReplace(aText, '%%number%%', aNumber + '');
I knew there was a reason, but in my eyes it is still a misbehaviour. I use generic code to replace %%field%% parameters in XML and rtf documents. Whenever I encounter a integer column, I have this problem. It is unexpected, because I ask this method to replace %%field%% by “1” and it replaces it by “1.0”. The problem is that I cannot determine the datatype of a column. So I can’t really take care of this myself. All I can do is create a calc that converts that integer to a text or do that workaround that I use know:
var aResult = utils.stringReplace(aText, ‘%%number%%’, aNumber + ‘’);
I don’t think it’s a 1.0, because the value comes from an integer column. And yes, there is a typeOf, but that doesn’t always do what you want it to (especially with dates). Anyway, I think it is easier to do a instanceOf in Java (so in the code of utils…) than messing around with JavaScript.
Yes, it’s Java only. But even: why should I do all kinds of if(typeOf(someField))… if I want to replace one thing by another. I just want the replaced result to be an integer, and not a 1000.0.
…but it does happen through Utils, I guess it’s an issue in the Utils library.