Browse Groups

• ## Re: [libertybasic] Re: Problem with "using"

(15)
• NextPrevious
• 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
Oct 1, 2001 1 of 15
View Source
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/
>
• 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)
Oct 1, 2001 1 of 15
View Source
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.
• 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
Oct 1, 2001 1 of 15
View Source
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?

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

> ----------
> From: R. Roumeas[SMTP:raymondroumeas@...]
> 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.
>
>
>
>
>
> To unsubscribe from this group, send an email to:
> libertybasic-unsubscribe@egroups.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
Oct 1, 2001 1 of 15
View Source
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
• 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
Oct 1, 2001 1 of 15
View Source
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
• 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
Oct 1, 2001 1 of 15
View Source
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

• I think that if you round 3.145556 to the first decimal place, the 5556 is not used. r.m. ... From: Moore, Brad To:
Oct 1, 2001 1 of 15
View Source
I think that if you round 3.145556 to the first decimal place,
the "5556" is not used.
r.m.

-----Original Message-----
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?
>
>Sr. Analyst - ADS Product Tracking MES Applications
>Weyerhaeuser Company
>Voice : (541) 756-9481
>Fax: (541) 756-7612
>
>> ----------
>> From: R. Roumeas[SMTP:raymondroumeas@...]
>> 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.
>>
>>
>>
>>
>>
>> To unsubscribe from this group, send an email to:
>> libertybasic-unsubscribe@egroups.com
>>
>>
>>
>>
>
>
>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/
>
• 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
Oct 2, 2001 1 of 15
View Source
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.
• ... 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
Oct 2, 2001 1 of 15
View Source
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.
To: