Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

can list operations be used to control the prfecision?

41 views
Skip to first unread message

johannes falcone

unread,
May 17, 2013, 5:56:14 PM5/17/13
to
liekif I want
2.3
2.5

not

2.3345234534534534535
2.5234523233534535455

I remember there was some complex way to stop this but you had ot change ti back or something after each op...

smeeded dangerous for prod code

tomás zerolo

unread,
May 21, 2013, 8:24:04 AM5/21/13
to
johannes falcone <vispha...@gmail.com> writes:

> liekif I want
> 2.3
> 2.5
>
> not
>
> 2.3345234534534534535
> 2.5234523233534535455

printf "%0.2f" 3.1415926535
=> 3.14

HTH
-- tomás

Donal K. Fellows

unread,
May 21, 2013, 9:27:43 AM5/21/13
to
On 21/05/2013 13:24, tomás zerolo wrote:
> printf "%0.2f" 3.1415926535
> => 3.14

I think you mean [format] there...

Donal.
--
Donal Fellows — Tcl user, Tcl maintainer, TIP editor.

tomás zerolo

unread,
May 21, 2013, 10:36:08 AM5/21/13
to
"Donal K. Fellows" <donal.k...@manchester.ac.uk> writes:

> On 21/05/2013 13:24, tomás zerolo wrote:
>> printf "%0.2f" 3.1415926535
>> => 3.14
>
> I think you mean [format] there...

Yes! Thanks for the catch.

(Actually, I did test the code... and it worked! But that was due to
tclsh picking up /usr/bin/printf via the [unknown] handler. Tsk, tsk :)

Regards
-- tomás

johannes falcone

unread,
May 25, 2013, 2:38:02 AM5/25/13
to
interesting

seems C ish

are you expected to know C to use tcl seriously?

tomás zerolo

unread,
May 25, 2013, 3:58:32 AM5/25/13
to
See Don's answer to my post. The function I used is printf, which on an
UNIXoid is typically in /usr/bin/printf (these days, at least). And this
one is definitely inspired in C's printf (which is itself inspired in...
but I disgress [1]).

As it turns out, it just worked by chance. The proc to use in Tcl is
[format] [2], which is itself inspired in... C's printf.

So yes, in some sense it helps knowing C's printf. But [2] helps too,
and is self-contained.

[1] <https://en.wikipedia.org/wiki/Printf>
[2] <https://www.tcl.tk/man/tcl8.4/TclCmd/format.htm>
0 new messages