Re: [SLUG] truncation in dc

From: ronan (ronan@tampabay.rr.com)
Date: Sat Jul 07 2007 - 08:21:29 EDT


Eben King wrote:
> Anyone know how to truncate values in dc(1)? I RTFMed but couldn't
> find it. For example:
>
> If I set the precision to three places:
>
> 3k
>
> and then calculate 1/3:
>
> 1 3/p
> .333
>
> It's correct. Supposing I only want one place to the right of the
> decimal point:
>
> 1k
>
> Adding 0 or 0.0, or multiplying by 1 or 1.0 won't work:
>
> 0+p
> .333
> 0.0+p
> .333
>
> 1*p
> .333
> 1.0*p
> .333
>
> So how do I do it?
>
Before doing your math, send "1 k" to set the precision to 1 decimal
place. For example:

1 k 1 3/p

yields:
.3

--ronan
-----------------------------------------------------------------------
This list is provided as an unmoderated internet service by Networked
Knowledge Systems (NKS). Views and opinions expressed in messages
posted are those of the author and do not necessarily reflect the
official policy or position of NKS or any of its employees.



This archive was generated by hypermail 2.1.3 : Fri Aug 01 2014 - 17:45:59 EDT