Thursday, April 1, 2010

FormattedStr2Num kernel function

Once I've read here that arithmetic expressions get evaluated in real edit form controls. It was an interesting fact that I didn't know. As an alternative way to evaluate arithmetic expressions runBuf and evalBuf kernel functions can be used, however they require code access permission validation.
Today I found yet another way to do the same thing - formattedStr2Num kernel function, which is designed to convert strings to reals but it accepts arithmetic expressions too. Probably it is the function invoked by form real edit control to evaluate user input.

Example:
formattedStr2Num('0.23 + 1 * (2 - 0,5)');
gives 1.73 as the result.

7 comments:

  1. Much better than my idea with the RealControl!
    Thank you for explaining this function (which seems I didn't know until now ...).

    ReplyDelete
  2. A good find indeed! I had found the blog post by Luegisdorf, and was looking for this method!

    ReplyDelete
  3. Well written and brilliantly executed blog and I just want to admire your writing skills because you have pulled this job in a quite unique manner which is very rare to see these days and I hope that you should share more and more in future also.
    Textile Industry Analysis

    ReplyDelete
  4. Very interesting post to read on and the main centre of attraction of this post is the choice of the title which catches the eyes of every reader quite easily and make it more readable and the presentation is also very good. Cheers to great work and hope to see more from you in future also.
    Latest Trends in Art

    ReplyDelete