zsh-users
 help / color / mirror / code / Atom feed
From: Phil Pennock <Phil.Pennock@globnix.org>
To: Borsenkow Andrej <Andrej.Borsenkow@mow.siemens.ru>
Cc: 'Bruno Bonfils' <asyd@debian-fr.org>, 'ZSH Users' <zsh-users@sunsite.dk>
Subject: Re: question about float variables
Date: Wed, 10 Oct 2001 11:42:25 +0200	[thread overview]
Message-ID: <20011010114224.A12923@globnix.org> (raw)
In-Reply-To: <001401c15169$c095c020$21c9ca95@mow.siemens.ru>; from Andrej.Borsenkow@mow.siemens.ru on Wed, Oct 10, 2001 at 12:58:38PM +0400

[-- Attachment #1: Type: text/plain, Size: 1352 bytes --]

On 2001-10-10 at 12:58 +0400, Borsenkow Andrej wrote:
> > float var1=0.0
> > var1=$((3 / 2))
> > echo $var1
> > 
> > return 1.000000000e+00 not good ! :(

> Integer divided by integer is integer.

Not so useful if you're manipulating parameters and you don't know what
their value is in advance.

% zmodload zsh/mathfunc
% float var1
% var1=$((float(3) / 2))
% echo $var1
1.500000000e+00

(Math-context float() is not the zsh command "float")

> > and how to format the output of $var1 ?
> > (i want a number like 95.3)

> typeset description:

They just change the storage type, so that:
% typeset -E var2
% typeset -F var3
% var2=$((3.0 / 2 )) ; var3=$((3.0 / 2 ))
% print $var2
1.500000000e+00
% print $var3
1.5000000000

I've not seen a way in zsh to modify this to be 'sensible' for humans,
as the original poster wants, unless you're happy to _just_ remove
trailing zeroes, in which case use the -F form and then:
% print ${var3%%0##}
1.5

Personally, I'd use the OS's printf(1) if it exists, and use the G
format specification; on OpenBSD:
 gG          The argument is printed in style f or in style e (E) whichev-
             er gives full precision in minimum space.

% printf '%g\n' $var2
1.5
% printf '%g\n' $var3
1.5

-- 
I don't like your use of the word "interesting" in this context.

[-- Attachment #2: Type: application/pgp-signature, Size: 187 bytes --]

  reply	other threads:[~2001-10-10  9:46 UTC|newest]

Thread overview: 6+ messages / expand[flat|nested]  mbox.gz  Atom feed  top
2001-10-09 23:33 Bruno Bonfils
2001-10-10  8:58 ` Borsenkow Andrej
2001-10-10  9:42   ` Phil Pennock [this message]
2001-10-10 10:10     ` Borsenkow Andrej
2001-10-10 10:28       ` Phil Pennock
2001-10-10 12:47   ` Bruno Bonfils

Reply instructions:

You may reply publicly to this message via plain-text email
using any one of the following methods:

* Save the following mbox file, import it into your mail client,
  and reply-to-all from there: mbox

  Avoid top-posting and favor interleaved quoting:
  https://en.wikipedia.org/wiki/Posting_style#Interleaved_style

* Reply using the --to, --cc, and --in-reply-to
  switches of git-send-email(1):

  git send-email \
    --in-reply-to=20011010114224.A12923@globnix.org \
    --to=phil.pennock@globnix.org \
    --cc=Andrej.Borsenkow@mow.siemens.ru \
    --cc=asyd@debian-fr.org \
    --cc=zsh-users@sunsite.dk \
    /path/to/YOUR_REPLY

  https://kernel.org/pub/software/scm/git/docs/git-send-email.html

* If your mail client supports setting the In-Reply-To header
  via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line before the message body.
Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/zsh/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).