help-bash
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

Re: Calculation


From: Greg Wooledge
Subject: Re: Calculation
Date: Sun, 20 Jun 2021 14:51:01 -0400

> > awk '
> >   {days = $1/150.0; sand = $1*0.04*1.8; cement = $1*0.04*15;
> >    bridge = $1*1.5/25; edgestripes = $1*1.5/50;
> >    printf("%.0f,%.0f,%.0f,%.0f,%.0f\n",
> >      days, sand, cement, bridge, edgestripes)
> >   }
> > ' size.txt
> 
> That looks interesting. AWK seems to be a powerful tool indeed. Awk rounds up
> how can still take the prices in there? 

Awk's printf uses the same rounding as bash's printf.  It's the standard
IEEE "banker's rounding" that I referred to earlier.

6.498 rounds to 6
6.499 rounds to 6
6.5   rounds to 6 ("round to even")
6.501 rounds to 7

> days take we first Entry from size.txt: 
> days: 90.25 / 150 = 0,601666667 = ~1 x (8/100) = 800
> sand: 6,498 ~ 7 = 7to. x 25 = 175
> cement: 90,25×0,04×15 = 54,15 = ~ 55 x 2 = 110
> ...

It's not clear to me what your rules are.  Especially, your claim that
6.498 should round to 7 does not follow the standard IEEE rules, nor does
it follow the explicit comparison to 0.499 that you were using initially.

I think I've covered all of the essential points already.  You should take
some extra time to play around with awk, or python, or whatever you choose
to go with.  Then decide exactly what rules you're trying to implement, and
finally write your program.



reply via email to

[Prev in Thread] Current Thread [Next in Thread]