How to round a text box value in the access form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • pugalenthi
    New Member
    • Jan 2007
    • 44

    How to round a text box value in the access form

    For example, i have a text box with value 1.6499999761581 4. How can i round it off to 1.7 ?.

    Is this possible using the text box control properties ?.
  • pugalenthi
    New Member
    • Jan 2007
    • 44

    #2
    Originally posted by pugalenthi
    For example, i have a text box with value 1.6499999761581 4. How can i round it off to 1.7 ?.

    Is this possible using the text box control properties ?.
    I actually use the query design view to generate the above value for a field. Is it possible to round off the above number using the Round() function in the query design.

    Comment

    • JKing
      Recognized Expert Top Contributor
      • Jun 2007
      • 1206

      #3
      You can set the control source of the textbox to the following:

      =Round([decimalField],1)

      Where "decimalFie ld" is name of the field you want to Round.
      The 1 represents the precision of rounding.

      Comment

      • pugalenthi
        New Member
        • Jan 2007
        • 44

        #4
        Originally posted by JKing
        You can set the control source of the textbox to the following:

        =Round([decimalField],1)

        Where "decimalFie ld" is name of the field you want to Round.
        The 1 represents the precision of rounding.
        AI_grade: ([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6

        the above gives the value 1.6499999761581 4 for field AI_grade. Now i need the value of AI_grade to be 1.7 after round off. How to do it in the same query?.

        Comment

        • JKing
          Recognized Expert Top Contributor
          • Jun 2007
          • 1206

          #5
          Originally posted by pugalenthi
          I actually use the query design view to generate the above value for a field. Is it possible to round off the above number using the Round() function in the query design.

          AI_grade: ([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6

          the above gives the value 1.6499999761581 4 for field AI_grade. Now i need the value of AI_grade to be 1.7 after round off. How to do it ?.
          Yes, this is also possible.
          The Round() function takes two parameters. The first is the value to be rounded and the second is the precision of the rounding. If you make your equation the first parameter and set the precision to 1 you should achieve your results.

          Example:
          Round( ([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6 , 1 )

          Comment

          • pugalenthi
            New Member
            • Jan 2007
            • 44

            #6
            Originally posted by JKing
            Yes, this is also possible.
            The Round() function takes two parameters. The first is the value to be rounded and the second is the precision of the rounding. If you make your equation the first parameter and set the precision to 1 you should achieve your results.

            Example:
            Round( ([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6 , 1 )

            I tried this already and got the value as 2 instead of 1.7. What could be wrong then ?.

            Comment

            • JKing
              Recognized Expert Top Contributor
              • Jun 2007
              • 1206

              #7
              It is very important that you set the precision to maintain decimals.

              If you simply put Round( equation) it will round to the nearest whole number.

              However, if you use Round( equation , 1 ) it will round to the first decimal place.

              Comment

              • pugalenthi
                New Member
                • Jan 2007
                • 44

                #8
                Originally posted by JKing
                It is very important that you set the precision to maintain decimals.

                If you simply put Round( equation) it will round to the nearest whole number.

                However, if you use Round( equation , 1 ) it will round to the first decimal place.
                This is how i tried,

                AI_grade: Round(([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6,1)

                and got the value for AI_grade as 2, instead of 1.7

                Comment

                • ADezii
                  Recognized Expert Expert
                  • Apr 2006
                  • 8834

                  #9
                  Originally posted by pugalenthi
                  This is how i tried,

                  AI_grade: Round(([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6,1)

                  and got the value for AI_grade as 2, instead of 1.7
                  [CODE=vb]Format(([AI_1_grade] * 3 + [AI_2_grade] + [AI_3_grade] * 2) / 6 , "#,###.#")[/CODE]

                  Comment

                  • pugalenthi
                    New Member
                    • Jan 2007
                    • 44

                    #10
                    Originally posted by ADezii
                    [CODE=vb]Format(([AI_1_grade] * 3 + [AI_2_grade] + [AI_3_grade] * 2) / 6 , "#,###.#")[/CODE]
                    I get a syntax error when i try the above in the query design.

                    Comment

                    • NeoPa
                      Recognized Expert Moderator MVP
                      • Oct 2006
                      • 32636

                      #11
                      Originally posted by pugalenthi
                      This is how i tried,

                      AI_grade: Round(([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6,1)

                      and got the value for AI_grade as 2, instead of 1.7
                      What's the formatting set to for the field AI_grade? I suspect this is your problem as Round(1.64999.. ., 1) does NOT return 2.

                      It may also help to explain that you want it rounded UP. Treating 1.64999... as 1.7 is certainly not rounding in the normal sense of the word.

                      Comment

                      • pugalenthi
                        New Member
                        • Jan 2007
                        • 44

                        #12
                        Originally posted by NeoPa
                        What's the formatting set to for the field AI_grade? I suspect this is your problem as Round(1.64999.. ., 1) does NOT return 2.

                        It may also help to explain that you want it rounded UP. Treating 1.64999... as 1.7 is certainly not rounding in the normal sense of the word.
                        I have set the formatting to Fixed, decimal places to 1 for the field AI_grade.

                        This is how i find AI_grade,

                        AI_grade: Round(([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6,1)

                        the value of the expression ([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6 is 1,6499999761581 4. I want this value to be rounded off to one decimal place, so that the value of AI_grade is 1,7. But the value what i get is 2,0 instead of 1,7 for AI_grade.

                        Comment

                        • sierra7
                          Recognized Expert Contributor
                          • Sep 2007
                          • 446

                          #13
                          Hi
                          The value you quote , 1.6499999761581 4 is less than 1.65000 etc, so should never automatically be rounded to 1.7

                          If you wish to force it to round UP , you must add something to it e.g 0.0001 depending upon the precision you require. You may wish to add 0.05, depending on you application and why you must round up.

                          A clue to the reason why you are getting 2.0 and not 1.6 may be that you are using a non-US keyboard. I notice in you last post that you used a comma (virgul) as the decimal separator character e.g.1,649999976 15814. This can lead to your code being mis-interpreted. I have experienced this before but can't remember the solution. I know that with an APPEND statement I had to put quotes around numbers as though they were character strings.

                          In this case I would try adding extra Brackets around the 'calculation' part to separate it from the ",1)" part:
                          Code:
                          AI_grade: Round((([AI_1_grade]*3+[AI_2_grade]+[AI_3_grade]*2)/6),1)
                          The alternative syntax proposed by Adezii is useful if you have numbers exceeding 1000, as 'thousand' separators are added, as defined by national setting.

                          S7

                          Comment

                          Working...