Loading ...
Sorry, an error occurred while loading the content.

Re: Problem with "using"

Expand Messages
  • rdomans@yahoo.com
    Carl, Thanks. Yes, I know. 859.79 was just a number that did not work correctly. And the rounding function was something I needed, not just an attempted fix
    Message 1 of 15 , Sep 30, 2001
    • 0 Attachment
      Carl,

      Thanks. Yes, I know. 859.79 was just a number that did not work
      correctly. And the rounding function was something I needed, not
      just an attempted fix for the using problem. I ended up doing this.

      tcost = xxxxx.xxxx
      cost$ = using("#######.##",round(tcost)+.0001)
      end

      function round(value)
      ----
      ---
      end function

      --- In libertybasic@y..., carlg@l... wrote:
      > Hi!
      >
      > The rounding function just returns 859.79, which is exactly what
      you
      > submit to it. Either way, the using functions is operating on the
      > same value. Try the following. It is simpler and doesn't require
      a
      > function, though you could write one using this approach.
      >
      > tcost = 859.79
      > cost$ = using("#######.##",tcost+0.005)
      > print cost$
      > end
      >
      > I'll have to revist why using() exhibits a loss of precision. In
      any
      > case the next version of Liberty BASIC will probably include a
      > version if using() which does rounding.
      >
      > -Carl
      >
      > --- In libertybasic@y..., rdomans@y... wrote:
      > >
      > > Thanks, Alyce and Eldron,
      > >
      > > Actually, I was using a rounding function before printing but
      > > I didn't think it was necessary to include in my original message
      > > because it still didn't work. Here's the original code.
      > >
      > > tcos = 859.79
      > > cost$ = using("#######.##",round(tcost))
      > > print cost$
      > > end
      > >
      > > function round(value)
      > > rounda = value * 100
      > > if abs(rounda-int(rounda)) < .5 then
      > > value = int(rounda)/100
      > > else
      > > if value>0 then roundb = int(rounda)+1
      > > if value<0 then roundb = int(rounda)-1
      > > value = roundb/100
      > > end if
      > > round = value
      > > end function
      > >
      > > (still prints 859.78)
      > >
      > > Alyce, one of the links you pointed me to mentioned not being able
      > > to use a fix with int(). So, I'm guessing this is why it doesn't
      > > work. I don't understand it so I'm just going to add .00001 to
      > > the number as suggested. Thanks to you both.
      > >
      > >
      > >
      > >
      > > --- In libertybasic@y..., rdomans@y... wrote:
      > > > Can anyone tell me what I'm doing wrong here?
      > > >
      > > > tcos = 859.79
      > > > cost$ = using("#######.##",tcos)
      > > > print cost$
      > > > end
      > > >
      > > > (prints 859.78)
      > > >
      > > > Bob D.
    • Richard Miller
      My method to avoid (or at least make less of a problem) the rounding error is to not enter decimal points, ever. Divide all printed numbers by 100 in the using
      Message 2 of 15 , Oct 1, 2001
      • 0 Attachment
        My method to avoid (or at least make less of a problem)
        the rounding error is to not enter decimal points, ever.
        Divide all printed numbers by 100 in the using statement, or elsewhere.
        r.m.

        -----Original Message-----
        From: rdomans@... <rdomans@...>
        To: libertybasic@yahoogroups.com <libertybasic@yahoogroups.com>
        Date: Sunday, September 30, 2001 5:39 PM
        Subject: [libertybasic] Re: Problem with "using"


        >Carl,
        >
        >Thanks. Yes, I know. 859.79 was just a number that did not work
        >correctly. And the rounding function was something I needed, not
        >just an attempted fix for the using problem. I ended up doing this.
        >
        > tcost = xxxxx.xxxx
        > cost$ = using("#######.##",round(tcost)+.0001)
        > end
        >
        > function round(value)
        > ----
        > ---
        > end function
        >
        >--- In libertybasic@y..., carlg@l... wrote:
        >> Hi!
        >>
        >> The rounding function just returns 859.79, which is exactly what
        >you
        >> submit to it. Either way, the using functions is operating on the
        >> same value. Try the following. It is simpler and doesn't require
        >a
        >> function, though you could write one using this approach.
        >>
        >> tcost = 859.79
        >> cost$ = using("#######.##",tcost+0.005)
        >> print cost$
        >> end
        >>
        >> I'll have to revist why using() exhibits a loss of precision. In
        >any
        >> case the next version of Liberty BASIC will probably include a
        >> version if using() which does rounding.
        >>
        >> -Carl
        >>
        >> --- In libertybasic@y..., rdomans@y... wrote:
        >> >
        >> > Thanks, Alyce and Eldron,
        >> >
        >> > Actually, I was using a rounding function before printing but
        >> > I didn't think it was necessary to include in my original message
        >> > because it still didn't work. Here's the original code.
        >> >
        >> > tcos = 859.79
        >> > cost$ = using("#######.##",round(tcost))
        >> > print cost$
        >> > end
        >> >
        >> > function round(value)
        >> > rounda = value * 100
        >> > if abs(rounda-int(rounda)) < .5 then
        >> > value = int(rounda)/100
        >> > else
        >> > if value>0 then roundb = int(rounda)+1
        >> > if value<0 then roundb = int(rounda)-1
        >> > value = roundb/100
        >> > end if
        >> > round = value
        >> > end function
        >> >
        >> > (still prints 859.78)
        >> >
        >> > Alyce, one of the links you pointed me to mentioned not being able
        >> > to use a fix with int(). So, I'm guessing this is why it doesn't
        >> > work. I don't understand it so I'm just going to add .00001 to
        >> > the number as suggested. Thanks to you both.
        >> >
        >> >
        >> >
        >> >
        >> > --- In libertybasic@y..., rdomans@y... wrote:
        >> > > Can anyone tell me what I'm doing wrong here?
        >> > >
        >> > > tcos = 859.79
        >> > > cost$ = using("#######.##",tcos)
        >> > > print cost$
        >> > > end
        >> > >
        >> > > (prints 859.78)
        >> > >
        >> > > Bob D.
        >
        >
        >
        >To unsubscribe from this group, send an email to:
        >libertybasic-unsubscribe@egroups.com
        >
        >
        >
        >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
        >
      • R. Roumeas
        Hi, here is my method to round to any decimal place. The second argument of the function is the number of decimal places. Try this: print round(3.1415926, 2)
        Message 3 of 15 , Oct 1, 2001
        • 0 Attachment
          Hi,
          here is my method to round to any decimal place. The second argument
          of the function is the number of decimal places. Try this:

          print round(3.1415926, 2)
          print round(3.1415926, 3)
          print round(3.1415926, 4)
          print round(-3.1415926, 5)
          print round(-3.1415926, 6)
          print round(-3.1415926, 7)

          input r$
          end


          function round(xx, n)
          k=10^n : roundxx = xx * k
          if abs(roundxx-int(roundxx)) < .5 then
          xx = int(roundxx)/k
          else
          round=int(roundxx)-(1-2*(xx>0))
          xx = round/k
          end if
          round = xx
          end function


          --- In libertybasic@y..., carlg@l... wrote:
          > Hi!
          >
          > The rounding function just returns 859.79, which is exactly what
          you
          > submit to it. Either way, the using functions is operating on the
          > same value. Try the following. It is simpler and doesn't require
          a
          > function, though you could write one using this approach.
          >
          > tcost = 859.79
          > cost$ = using("#######.##",tcost+0.005)
          > print cost$
          > end
          >
          > I'll have to revist why using() exhibits a loss of precision. In
          any
          > case the next version of Liberty BASIC will probably include a
          > version if using() which does rounding.
          >
          > -Carl
          >
          > --- In libertybasic@y..., rdomans@y... wrote:
          > >
          > > Thanks, Alyce and Eldron,
          > >
          > > Actually, I was using a rounding function before printing but
          > > I didn't think it was necessary to include in my original message
          > > because it still didn't work. Here's the original code.
          > >
          > > tcos = 859.79
          > > cost$ = using("#######.##",round(tcost))
          > > print cost$
          > > end
          > >
          > > function round(value)
          > > rounda = value * 100
          > > if abs(rounda-int(rounda)) < .5 then
          > > value = int(rounda)/100
          > > else
          > > if value>0 then roundb = int(rounda)+1
          > > if value<0 then roundb = int(rounda)-1
          > > value = roundb/100
          > > end if
          > > round = value
          > > end function
          > >
          > > (still prints 859.78)
          > >
          > > Alyce, one of the links you pointed me to mentioned not being able
          > > to use a fix with int(). So, I'm guessing this is why it doesn't
          > > work. I don't understand it so I'm just going to add .00001 to
          > > the number as suggested. Thanks to you both.
          > >
          > >
          > >
          > >
          > > --- In libertybasic@y..., rdomans@y... wrote:
          > > > Can anyone tell me what I'm doing wrong here?
          > > >
          > > > tcos = 859.79
          > > > cost$ = using("#######.##",tcos)
          > > > print cost$
          > > > end
          > > >
          > > > (prints 859.78)
          > > >
          > > > Bob D.
        • Moore, Brad
          Yes, but what is 3.145556 rounded to the first decimal place? Doesn t the 5556 all round from one to the next then rounding the 4 up to 5 causing the
          Message 4 of 15 , Oct 1, 2001
          • 0 Attachment
            Yes, but what is 3.145556 rounded to the first decimal place? Doesn't the
            '5556' all round from one to the next then rounding the '4' up to '5'
            causing the actual rounded value to be 3.2? I seem to remember this from
            somewhere, but my math skills are getting a little rusty. Any math experts
            out there?

            Brad Moore
            Sr. Analyst - ADS Product Tracking MES Applications
            Weyerhaeuser Company
            Voice : (541) 756-9481
            Fax: (541) 756-7612
            brad.moore@...

            > ----------
            > From: R. Roumeas[SMTP:raymondroumeas@...]
            > Reply To: libertybasic@yahoogroups.com
            > Sent: Monday, October 01, 2001 1:02 PM
            > To: libertybasic@yahoogroups.com
            > Subject: [libertybasic] Re: Problem with "using"
            >
            > Hi,
            > here is my method to round to any decimal place. The second argument
            > of the function is the number of decimal places. Try this:
            >
            > print round(3.1415926, 2)
            > print round(3.1415926, 3)
            > print round(3.1415926, 4)
            > print round(-3.1415926, 5)
            > print round(-3.1415926, 6)
            > print round(-3.1415926, 7)
            >
            > input r$
            > end
            >
            >
            > function round(xx, n)
            > k=10^n : roundxx = xx * k
            > if abs(roundxx-int(roundxx)) < .5 then
            > xx = int(roundxx)/k
            > else
            > round=int(roundxx)-(1-2*(xx>0))
            > xx = round/k
            > end if
            > round = xx
            > end function
            >
            >
            > --- In libertybasic@y..., carlg@l... wrote:
            > > Hi!
            > >
            > > The rounding function just returns 859.79, which is exactly what
            > you
            > > submit to it. Either way, the using functions is operating on the
            > > same value. Try the following. It is simpler and doesn't require
            > a
            > > function, though you could write one using this approach.
            > >
            > > tcost = 859.79
            > > cost$ = using("#######.##",tcost+0.005)
            > > print cost$
            > > end
            > >
            > > I'll have to revist why using() exhibits a loss of precision. In
            > any
            > > case the next version of Liberty BASIC will probably include a
            > > version if using() which does rounding.
            > >
            > > -Carl
            > >
            > > --- In libertybasic@y..., rdomans@y... wrote:
            > > >
            > > > Thanks, Alyce and Eldron,
            > > >
            > > > Actually, I was using a rounding function before printing but
            > > > I didn't think it was necessary to include in my original message
            > > > because it still didn't work. Here's the original code.
            > > >
            > > > tcos = 859.79
            > > > cost$ = using("#######.##",round(tcost))
            > > > print cost$
            > > > end
            > > >
            > > > function round(value)
            > > > rounda = value * 100
            > > > if abs(rounda-int(rounda)) < .5 then
            > > > value = int(rounda)/100
            > > > else
            > > > if value>0 then roundb = int(rounda)+1
            > > > if value<0 then roundb = int(rounda)-1
            > > > value = roundb/100
            > > > end if
            > > > round = value
            > > > end function
            > > >
            > > > (still prints 859.78)
            > > >
            > > > Alyce, one of the links you pointed me to mentioned not being able
            > > > to use a fix with int(). So, I'm guessing this is why it doesn't
            > > > work. I don't understand it so I'm just going to add .00001 to
            > > > the number as suggested. Thanks to you both.
            > > >
            > > >
            > > >
            > > >
            > > > --- In libertybasic@y..., rdomans@y... wrote:
            > > > > Can anyone tell me what I'm doing wrong here?
            > > > >
            > > > > tcos = 859.79
            > > > > cost$ = using("#######.##",tcos)
            > > > > print cost$
            > > > > end
            > > > >
            > > > > (prints 859.78)
            > > > >
            > > > > Bob D.
            >
            >
            >
            > Yahoo! Groups Sponsor
            > ADVERTISEMENT
            > Click Here!
            >
            >
            > To unsubscribe from this group, send an email to:
            > libertybasic-unsubscribe@egroups.com
            >
            >
            >
            > Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
            >
          • Chergarj@cs.com
            In a message dated 10/01/2001 1:05:53 PM Pacific Daylight Time, ... I feel like I have a hole in my head. What is the xx supposed to mean? Does it have to
            Message 5 of 15 , Oct 1, 2001
            • 0 Attachment
              In a message dated 10/01/2001 1:05:53 PM Pacific Daylight Time, raymondroumeas@... writes:


              print round(3.1415926, 2)
              print round(3.1415926, 3)
              print round(3.1415926, 4)
              print round(-3.1415926, 5)
              print round(-3.1415926, 6)
              print round(-3.1415926, 7)

              input r$
              end


              function round(xx, n)
                 k=10^n : roundxx = xx * k
                 if abs(roundxx-int(roundxx)) < .5 then
                     xx = int(roundxx)/k
                 else
                     round=int(roundxx)-(1-2*(xx>0))
                     xx = round/k
                 end if
                 round = xx
                 end function



              I feel like I have a hole in my head.  What is the "xx" supposed to mean?  Does it have to be xx, or can it be simply x?

              G C
            • Chergarj@cs.com
              In a message dated 10/01/2001 1:16:03 PM Pacific Daylight Time, ... ... to the first decimal place? means to the tenths place, the digit in the place just
              Message 6 of 15 , Oct 1, 2001
              • 0 Attachment
                In a message dated 10/01/2001 1:16:03 PM Pacific Daylight Time, brad.moore@... writes:


                Yes, but what is 3.145556 rounded to the first decimal place?  Doesn't the
                '5556' all round from one to the next then rounding the '4' up to '5'
                causing the actual rounded value to be 3.2?  I seem to remember this from
                somewhere, but my math skills are getting a little rusty.  Any math experts
                out there?


                "... to the first decimal place?"  means to the tenths place, the digit in the place just to the right-hand side of the decimal point.  To round to the tenths place, inspect the digit in that place.  Now examine the digit in the next place to the right.  Is it 5 or greater?  If yes, then round up ( the 1 in the tenths place must be made 2)
                If no, then do not change but keep the digit in the tenths place as it is (the 1 remains as a 1).  
                To round 3.145556 to the nearest tenths, your result is 3.1

                G C
              • Richard Miller
                the field names in a function list can be anything you choose, but the sequence of the names must be the same as in the calling statement Also, numeric fields
                Message 7 of 15 , Oct 1, 2001
                • 0 Attachment
                  the field names in a function list can be anything you choose,
                  but the sequence of the names must be the same as in the calling statement
                  Also, numeric fields can not end with a $, and string fields must end with a $
                  r.m.
                   
                  -----Original Message-----
                  From: Chergarj@... <Chergarj@...>
                  To: libertybasic@yahoogroups.com <libertybasic@yahoogroups.com>
                  Cc: Chergarj@... <Chergarj@...>
                  Date: Monday, October 01, 2001 10:22 AM
                  Subject: Re: [libertybasic] Re: Problem with "using"

                  In a message dated 10/01/2001 1:05:53 PM Pacific Daylight Time, raymondroumeas@... writes:


                  print round(3.1415926, 2)
                  print round(3.1415926, 3)
                  print round(3.1415926, 4)
                  print round(-3.1415926, 5)
                  print round(-3.1415926, 6)
                  print round(-3.1415926, 7)

                  input r$
                  end


                  function round(xx, n)
                     k=10^n : roundxx = xx * k
                     if abs(roundxx-int(roundxx)) < .5 then
                         xx = int(roundxx)/k
                     else
                         round=int(roundxx)-(1-2*(xx>0))
                         xx = round/k
                     end if
                     round = xx
                     end function



                  I feel like I have a hole in my head.  What is the "xx" supposed to mean?  Does it have to be xx, or can it be simply x?

                  G C


                  To unsubscribe from this group, send an email to:
                  libertybasic-unsubscribe@egroups.com



                  Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                • Richard Miller
                  I think that if you round 3.145556 to the first decimal place, the 5556 is not used. r.m. ... From: Moore, Brad To:
                  Message 8 of 15 , Oct 1, 2001
                  • 0 Attachment
                    I think that if you round 3.145556 to the first decimal place,
                    the "5556" is not used.
                    r.m.

                    -----Original Message-----
                    From: Moore, Brad <brad.moore@...>
                    To: 'libertybasic@yahoogroups.com' <libertybasic@yahoogroups.com>
                    Date: Monday, October 01, 2001 10:09 AM
                    Subject: RE: [libertybasic] Re: Problem with "using"


                    >Yes, but what is 3.145556 rounded to the first decimal place? Doesn't the
                    >'5556' all round from one to the next then rounding the '4' up to '5'
                    >causing the actual rounded value to be 3.2? I seem to remember this from
                    >somewhere, but my math skills are getting a little rusty. Any math experts
                    >out there?
                    >
                    >Brad Moore
                    >Sr. Analyst - ADS Product Tracking MES Applications
                    >Weyerhaeuser Company
                    >Voice : (541) 756-9481
                    >Fax: (541) 756-7612
                    >brad.moore@...
                    >
                    >> ----------
                    >> From: R. Roumeas[SMTP:raymondroumeas@...]
                    >> Reply To: libertybasic@yahoogroups.com
                    >> Sent: Monday, October 01, 2001 1:02 PM
                    >> To: libertybasic@yahoogroups.com
                    >> Subject: [libertybasic] Re: Problem with "using"
                    >>
                    >> Hi,
                    >> here is my method to round to any decimal place. The second argument
                    >> of the function is the number of decimal places. Try this:
                    >>
                    >> print round(3.1415926, 2)
                    >> print round(3.1415926, 3)
                    >> print round(3.1415926, 4)
                    >> print round(-3.1415926, 5)
                    >> print round(-3.1415926, 6)
                    >> print round(-3.1415926, 7)
                    >>
                    >> input r$
                    >> end
                    >>
                    >>
                    >> function round(xx, n)
                    >> k=10^n : roundxx = xx * k
                    >> if abs(roundxx-int(roundxx)) < .5 then
                    >> xx = int(roundxx)/k
                    >> else
                    >> round=int(roundxx)-(1-2*(xx>0))
                    >> xx = round/k
                    >> end if
                    >> round = xx
                    >> end function
                    >>
                    >>
                    >> --- In libertybasic@y..., carlg@l... wrote:
                    >> > Hi!
                    >> >
                    >> > The rounding function just returns 859.79, which is exactly what
                    >> you
                    >> > submit to it. Either way, the using functions is operating on the
                    >> > same value. Try the following. It is simpler and doesn't require
                    >> a
                    >> > function, though you could write one using this approach.
                    >> >
                    >> > tcost = 859.79
                    >> > cost$ = using("#######.##",tcost+0.005)
                    >> > print cost$
                    >> > end
                    >> >
                    >> > I'll have to revist why using() exhibits a loss of precision. In
                    >> any
                    >> > case the next version of Liberty BASIC will probably include a
                    >> > version if using() which does rounding.
                    >> >
                    >> > -Carl
                    >> >
                    >> > --- In libertybasic@y..., rdomans@y... wrote:
                    >> > >
                    >> > > Thanks, Alyce and Eldron,
                    >> > >
                    >> > > Actually, I was using a rounding function before printing but
                    >> > > I didn't think it was necessary to include in my original message
                    >> > > because it still didn't work. Here's the original code.
                    >> > >
                    >> > > tcos = 859.79
                    >> > > cost$ = using("#######.##",round(tcost))
                    >> > > print cost$
                    >> > > end
                    >> > >
                    >> > > function round(value)
                    >> > > rounda = value * 100
                    >> > > if abs(rounda-int(rounda)) < .5 then
                    >> > > value = int(rounda)/100
                    >> > > else
                    >> > > if value>0 then roundb = int(rounda)+1
                    >> > > if value<0 then roundb = int(rounda)-1
                    >> > > value = roundb/100
                    >> > > end if
                    >> > > round = value
                    >> > > end function
                    >> > >
                    >> > > (still prints 859.78)
                    >> > >
                    >> > > Alyce, one of the links you pointed me to mentioned not being able
                    >> > > to use a fix with int(). So, I'm guessing this is why it doesn't
                    >> > > work. I don't understand it so I'm just going to add .00001 to
                    >> > > the number as suggested. Thanks to you both.
                    >> > >
                    >> > >
                    >> > >
                    >> > >
                    >> > > --- In libertybasic@y..., rdomans@y... wrote:
                    >> > > > Can anyone tell me what I'm doing wrong here?
                    >> > > >
                    >> > > > tcos = 859.79
                    >> > > > cost$ = using("#######.##",tcos)
                    >> > > > print cost$
                    >> > > > end
                    >> > > >
                    >> > > > (prints 859.78)
                    >> > > >
                    >> > > > Bob D.
                    >>
                    >>
                    >>
                    >> Yahoo! Groups Sponsor
                    >> ADVERTISEMENT
                    >> Click Here!
                    >>
                    >>
                    >> To unsubscribe from this group, send an email to:
                    >> libertybasic-unsubscribe@egroups.com
                    >>
                    >>
                    >>
                    >> Your use of Yahoo! Groups is subject to the Yahoo! Terms of Service.
                    >>
                    >
                    >
                    >To unsubscribe from this group, send an email to:
                    >libertybasic-unsubscribe@egroups.com
                    >
                    >
                    >
                    >Your use of Yahoo! Groups is subject to http://docs.yahoo.com/info/terms/
                    >
                  • R. Roumeas
                    Hi everybody, Sorry the code was not documented. I thought that the test examples were explicit enough. The xx variable in the function is local, it could have
                    Message 9 of 15 , Oct 2, 2001
                    • 0 Attachment
                      Hi everybody,

                      Sorry the code was not documented. I thought that the test examples
                      were explicit enough.

                      The xx variable in the function is local, it could have been any name
                      including "x", "y", "z" or even "Raymond" ;-)

                      The first argument of the function is the number to be rounded, the
                      second argument tells the function how many decimal places are
                      requested after the decimal point.

                      I forgot also to mention that the trick to add 1 or substract 1
                      according to the result of the test (xx>0) was explained by Alyce in
                      some newsletter quite a while ago. It's a smart way to replace a
                      if..then..else statement by an calculated expression:

                      > round=int(roundxx)-(1-2*(xx>0))

                      Thanks Alyce

                      --- In libertybasic@y..., "R. Roumeas" <raymondroumeas@y...> wrote:
                      > Hi,
                      > here is my method to round to any decimal place. The second argument
                      > of the function is the number of decimal places. Try this:
                      >
                      > print round(3.1415926, 2)
                      > print round(3.1415926, 3)
                      > print round(3.1415926, 4)
                      > print round(-3.1415926, 5)
                      > print round(-3.1415926, 6)
                      > print round(-3.1415926, 7)
                      >
                      > input r$
                      > end
                      >
                      >
                      > function round(xx, n)
                      > k=10^n : roundxx = xx * k
                      > if abs(roundxx-int(roundxx)) < .5 then
                      > xx = int(roundxx)/k
                      > else
                      > round=int(roundxx)-(1-2*(xx>0))
                      > xx = round/k
                      > end if
                      > round = xx
                      > end function
                      >
                      >
                      > --- In libertybasic@y..., carlg@l... wrote:
                      > > Hi!
                      > >
                      > > The rounding function just returns 859.79, which is exactly what
                      > you
                      > > submit to it. Either way, the using functions is operating on the
                      > > same value. Try the following. It is simpler and doesn't require
                      > a
                      > > function, though you could write one using this approach.
                      > >
                      > > tcost = 859.79
                      > > cost$ = using("#######.##",tcost+0.005)
                      > > print cost$
                      > > end
                      > >
                      > > I'll have to revist why using() exhibits a loss of precision. In
                      > any
                      > > case the next version of Liberty BASIC will probably include a
                      > > version if using() which does rounding.
                      > >
                      > > -Carl
                      > >
                      > > --- In libertybasic@y..., rdomans@y... wrote:
                      > > >
                      > > > Thanks, Alyce and Eldron,
                      > > >
                      > > > Actually, I was using a rounding function before printing but
                      > > > I didn't think it was necessary to include in my original
                      message
                      > > > because it still didn't work. Here's the original code.
                      > > >
                      > > > tcos = 859.79
                      > > > cost$ = using("#######.##",round(tcost))
                      > > > print cost$
                      > > > end
                      > > >
                      > > > function round(value)
                      > > > rounda = value * 100
                      > > > if abs(rounda-int(rounda)) < .5 then
                      > > > value = int(rounda)/100
                      > > > else
                      > > > if value>0 then roundb = int(rounda)+1
                      > > > if value<0 then roundb = int(rounda)-1
                      > > > value = roundb/100
                      > > > end if
                      > > > round = value
                      > > > end function
                      > > >
                      > > > (still prints 859.78)
                      > > >
                      > > > Alyce, one of the links you pointed me to mentioned not being
                      able
                      > > > to use a fix with int(). So, I'm guessing this is why it doesn't
                      > > > work. I don't understand it so I'm just going to add .00001 to
                      > > > the number as suggested. Thanks to you both.
                      > > >
                      > > >
                      > > >
                      > > >
                      > > > --- In libertybasic@y..., rdomans@y... wrote:
                      > > > > Can anyone tell me what I'm doing wrong here?
                      > > > >
                      > > > > tcos = 859.79
                      > > > > cost$ = using("#######.##",tcos)
                      > > > > print cost$
                      > > > > end
                      > > > >
                      > > > > (prints 859.78)
                      > > > >
                      > > > > Bob D.
                    • Allen Mellen
                      ... If I recall correctly, in GWBasic, we had to add .005001 to be accurate in every case. Or maybe that was in IBM s Call360 Basic. Allen
                      Message 10 of 15 , Oct 2, 2001
                      • 0 Attachment
                        Carl wrote:

                        >The rounding function just returns 859.79, which is exactly what you
                        >submit to it. Either way, the using functions is operating on the
                        >same value. Try the following. It is simpler and doesn't require a
                        >function, though you could write one using this approach.
                        >
                        > tcost = 859.79
                        > cost$ = using("#######.##",tcost+0.005)
                        > print cost$
                        > end
                        >
                        >I'll have to revist why using() exhibits a loss of precision. In any
                        >case the next version of Liberty BASIC will probably include a
                        >version if using() which does rounding.

                        If I recall correctly, in GWBasic, we had to add .005001 to be accurate in
                        every case. Or maybe that was in IBM's Call360 Basic. <g>

                        Allen
                      Your message has been successfully submitted and would be delivered to recipients shortly.