Alpha Software Mobile Development Tools:   Alpha Anywhere    |   Alpha TransForm subscribe to our YouTube Channel  Follow Us on LinkedIn  Follow Us on Twitter  Follow Us on Facebook

Announcement

Collapse

The Alpha Software Forum Participation Guidelines

The Alpha Software Forum is a free forum created for Alpha Software Developer Community to ask for help, exchange ideas, and share solutions. Alpha Software strives to create an environment where all members of the community can feel safe to participate. In order to ensure the Alpha Software Forum is a place where all feel welcome, forum participants are expected to behave as follows:
  • Be professional in your conduct
  • Be kind to others
  • Be constructive when giving feedback
  • Be open to new ideas and suggestions
  • Stay on topic


Be sure all comments and threads you post are respectful. Posts that contain any of the following content will be considered a violation of your agreement as a member of the Alpha Software Forum Community and will be moderated:
  • Spam.
  • Vulgar language.
  • Quotes from private conversations without permission, including pricing and other sales related discussions.
  • Personal attacks, insults, or subtle put-downs.
  • Harassment, bullying, threatening, mocking, shaming, or deriding anyone.
  • Sexist, racist, homophobic, transphobic, ableist, or otherwise discriminatory jokes and language.
  • Sexually explicit or violent material, links, or language.
  • Pirated, hacked, or copyright-infringing material.
  • Encouraging of others to engage in the above behaviors.


If a thread or post is found to contain any of the content outlined above, a moderator may choose to take one of the following actions:
  • Remove the Post or Thread - the content is removed from the forum.
  • Place the User in Moderation - all posts and new threads must be approved by a moderator before they are posted.
  • Temporarily Ban the User - user is banned from forum for a period of time.
  • Permanently Ban the User - user is permanently banned from the forum.


Moderators may also rename posts and threads if they are too generic or do not property reflect the content.

Moderators may move threads if they have been posted in the incorrect forum.

Threads/Posts questioning specific moderator decisions or actions (such as "why was a user banned?") are not allowed and will be removed.

The owners of Alpha Software Corporation (Forum Owner) reserve the right to remove, edit, move, or close any thread for any reason; or ban any forum member without notice, reason, or explanation.

Community members are encouraged to click the "Report Post" icon in the lower left of a given post if they feel the post is in violation of the rules. This will alert the Moderators to take a look.

Alpha Software Corporation may amend the guidelines from time to time and may also vary the procedures it sets out where appropriate in a particular case. Your agreement to comply with the guidelines will be deemed agreement to any changes to it.



Bonus TIPS for Successful Posting

Try a Search First
It is highly recommended that a Search be done on your topic before posting, as many questions have been answered in prior posts. As with any search engine, the shorter the search term, the more "hits" will be returned, but the more specific the search term is, the greater the relevance of those "hits". Searching for "table" might well return every message on the board while "tablesum" would greatly restrict the number of messages returned.

When you do post
First, make sure you are posting your question in the correct forum. For example, if you post an issue regarding Desktop applications on the Mobile & Browser Applications board , not only will your question not be seen by the appropriate audience, it may also be removed or relocated.

The more detail you provide about your problem or question, the more likely someone is to understand your request and be able to help. A sample database with a minimum of records (and its support files, zipped together) will make it much easier to diagnose issues with your application. Screen shots of error messages are especially helpful.

When explaining how to reproduce your problem, please be as detailed as possible. Describe every step, click-by-click and keypress-by-keypress. Otherwise when others try to duplicate your problem, they may do something slightly different and end up with different results.

A note about attachments
You may only attach one file to each message. Attachment file size is limited to 2MB. If you need to include several files, you may do so by zipping them into a single archive.

If you forgot to attach your files to your post, please do NOT create a new thread. Instead, reply to your original message and attach the file there.

When attaching screen shots, it is best to attach an image file (.BMP, .JPG, .GIF, .PNG, etc.) or a zip file of several images, as opposed to a Word document containing the screen shots. Because Word documents are prone to viruses, many message board users will not open your Word file, therefore limiting their ability to help you.

Similarly, if you are uploading a zipped archive, you should simply create a .ZIP file and not a self-extracting .EXE as many users will not run your EXE file.
See more
See less

Strange val() behaviour in V12

Collapse
X
 
  • Filter
  • Time
  • Show
Clear All
new posts

    Strange val() behaviour in V12

    Hi All,

    In V12 if I run this simple script in the interactive window, the resulting number in balance comes out like this 1887.7999999999993

    debug(1)

    dim test as c
    dim test2 as c

    test = "12322.34"
    test2 = "10434.54"

    dim balance as c

    balance = val(test) - val(test2)

    The same script in V10.5 returns a proper value. Any ideas why Val() is returning such a funky number in V12?

    #2
    Re: Strange val() behaviour in V12

    Not sure why you have
    dim balance as c
    rather than
    dim balance as n
    I am sure that :
    balance = convert_type(val(test) - val(test2),"c")
    is good practice and will always work and survive changes.

    If you really want balance as c (not in front of a V12 pc with V12 at present).
    probably this also works (I saw Selwyn use it in a video):
    balance = "" + (val(test) - val(test2))

    We are sometimes spoilt by Alpha allowing us to not be 100% correct with data types but long term code will always be more robust if we are.
    Hope this helps.

    Comment


      #3
      Re: Strange val() behaviour in V12

      Garry,

      Not sure I understand your point:

      Code:
      test = "12322.34"
      
      test2 = "10434.54"
      
      
      ? val(test) - val(test2)
      = 1887.7999999999993
      
      ? convert_type(val(test) - val(test2),"c")
      = "1887.7999999999993"
      Peter
      AlphaBase Solutions, LLC

      [email protected]
      https://www.alphabasesolutions.com


      Comment


        #4
        Re: Strange val() behaviour in V12

        It has nothing to do with val() behavior or any other functions.
        We know from waa....aaay back that the 8086 maths processsor works to 18 decimal places over multiple iterations, and when pushed to more decimal places than you need you will see this

        test = 12322.34
        test2 = 10434.54
        ?str(test-test2,30,20)
        = "1887.799999999999300"

        Comment


          #5
          Re: Strange val() behaviour in V12

          Peter, as I mentioned, I was not in front of V12 to test and now I see from others that I was way off track, so I did not have a valid point

          Comment


            #6
            Re: Strange val() behaviour in V12

            Unless I am mistaken, the point behind using the character variables, "dim test as c", in the post is because in xBasic your numeric data from window controls on your components usually comes back to you in xBasic as the CHARACTER data type.

            Comment


              #7
              Re: Strange val() behaviour in V12

              Absolutely not.
              This is a bad example, don't be misled.

              Comment


                #8
                Re: Strange val() behaviour in V12

                window controls on your components usually comes back to you in xBasic as the CHARACTER data type.
                hello

                are you referring to web, on the web all are characters, as far as i know.
                thanks for reading

                gandhi

                version 11 3381 - 4096
                mysql backend
                http://www.alphawebprogramming.blogspot.com
                [email protected]
                Skype:[email protected]
                1 914 924 5171

                Comment


                  #9
                  Re: Strange val() behaviour in V12

                  Perhaps, adopting Scott's code to work with two MONEY fields in a web app with a SQL DB will demonstrate the significance if this issue.

                  Make a grid with updateable detail view that includes two controls associated to SQL "money" columns. Put something like the following in the server-side AfterUpdateRecord event:


                  dim str as C
                  str = "xBasic Variable Type for SQL MONEY column = " + typeof(e.DataSubmitted.ProductPrice) + crlf() + \
                  "Value1= " + e.DataSubmitted.ProductPrice + " Value2= " + e.DataSubmitted.Price2 + crlf() + \
                  "Difference = " + ( val(e.DataSubmitted.ProductPrice) - val(e.DataSubmitted.Price2)) + crlf() + \
                  "Using 'Convert_Type' Difference = " + (convert_type(e.DataSubmitted.ProductPrice,"N") - convert_type(e.DataSubmitted.Price2,"N")) + crlf()

                  aa = e.rtc.A_AjaxResponses
                  aa[].text = "alert('" + js_escape(str) + "');"
                  aa[..].id = 100

                  Using scotts example values I get the following value in STR:

                  xBasic Variable Type for SQL MONEY column = C
                  Value1= 12322.34 Value2= 10434.54
                  Difference = 1887.7999999999993
                  Using 'Convert_Type' Difference = 1887.7999999999993�

                  Comment


                    #10
                    Re: Strange val() behaviour in V12

                    I am submitting this as a bug to Alpha.

                    Comment


                      #11
                      Re: Strange val() behaviour in V12

                      You really don't get it!
                      There is no issue
                      there is no bug
                      This goes way back to the maths co-processor 8086 functions - look it up.
                      It has nothing to do with alpha.
                      Where in reality do you expect to calculate numbers in a string and then to 14 decimals?.
                      At 2 or 3 or even 10 decimals this is still numerically 1887.8

                      Comment


                        #12
                        Re: Strange val() behaviour in V12

                        "Really!" Ray?

                        You are going to content that the following output from my Xbasic interactive window is acceptable output for a business class development environment? This might be acceptable output if you were writing an interpretive compiler at the highschool class project level.

                        ?version("V") + "." + Version("B") + " " + version("E")
                        = "12.0.1620 Developers edition"

                        dim var1 as N = 12322.34
                        dim var2 as N = 10434.54
                        dim diff as N
                        diff = var1 - var2
                        ?diff
                        = 1887.7999999999993

                        Comment


                          #13
                          Re: Strange val() behaviour in V12

                          No I'm not asserting anything, it is not my contention. As I said, research it there are hundreds of references to addition and subtraction by the processor/ This is the first hit on google

                          http://flint.cs.yale.edu/cs422/doc/a...m/pdf/CH14.PDF

                          Comment


                            #14
                            Re: Strange val() behaviour in V12

                            Hey Everyone,

                            Thanks for all the input! For my own personal needs I was simply subtracting one dollar amount from another. So obviously I don't want the return value to be .343434434 etc. To fix the current issue I simply added the round command to two decimal places after the return value.

                            dim total_balance as c
                            dim total_credit as c

                            total_balance = rs.data(1)
                            total_credit = rs.data(2)

                            delete balance
                            dim balance as c

                            balance = val(total_balance) - val(total_credit)

                            balance = round(val(balance),2)

                            However, in reading through the thread it seems there are two questions.....

                            1) When working with dollar amounts, what is the best way to subtract two figures in Xbasic to get a result with only two decimal places..

                            2) A more technical discussion which I don't claim to fully understand at this point on how Alpha Five works with certain computations.

                            Curious to see what Alpha thinks!

                            Cheers,

                            Scott

                            Comment


                              #15
                              Re: Strange val() behaviour in V12

                              Ray, I did not notice any mention of packed decimal formats in the article you referenced. Packed decimal number format is expected, and usually required, for software developed for financial institutions:

                              dec Number library
                              LibP BCD/
                              Microsoft CLR DECIMAL
                              intel-decimal-floating-point-math-library

                              Comment

                              Working...
                              X