table.stringField = any2str(dynamicObject);Sweet. Everything compiles, let's continue writing code.
Ok, time to run a test. What? Run-time error? Method is expecting object of type string? Wait, what line is it talking about?
For a moment I refused to believe that someone wouldn't have been so stupid to code up this method to expect only strings to be passed in. And even after I realized that was the truth, I still couldn't believe it. Yes, the method does in fact take in an anytype. However, the method only works if that anytype is of type string. So, instead of using the intuitive knowledge us developers have been taught to use, we have to now second guess every kernel function we call into no matter how we much "know" (think) how a method should work. We've been duped, we've been given a useless str2str() method.
The workaround is below. Use this as a local function (or as a method in the Global class to make a global method) inside the methods you often would use any2str(), that is, before understanding what the method really does.
str theRealAny2str(anytype _val)
return date2str(any2date(_val), 213, 2, -1, 2, -1, 2);
return num2str(any2real(_val), 1, 2, 1, 0);
You can try this it is simpler and more accurate , avoiding fixed decimals for reals
str myAny2str(anytype _val)