- 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/

> - Carl wrote:

>The rounding function just returns 859.79, which is exactly what you

If I recall correctly, in GWBasic, we had to add .005001 to be accurate in

>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.

every case. Or maybe that was in IBM's Call360 Basic. <g>

Allen