• division par 1000 en bash

    From zeneca@3:770/3 to All on Wed Oct 6 17:28:53 2021
    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765

    let NUM=$TOT/1000

    (( NUU=$TOT/1000))

    echo "$TOT $NUM $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From A. Dumas@3:770/3 to BIG Umberto on Wed Oct 6 16:16:03 2021
    BIG Umberto <user@langnese.nvg.unit.no> wrote:
    In date: Wed, 06 Oct 2021 17:28:53 on group: comp.sys.raspberry-pi,
    zeneca wrote:
    #/bin/bash

    TOT=21765
    let NUM=$TOT/1000
    (( NUU=$TOT/1000))
    echo "$TOT $NUM $NUU"

    le resulta est 21
    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance

    Bash use ONLY INTEGER numbers!

    Yes. You can install 'bc' to do more math in scripts, for example:

    R=$(echo 'scale=3;21765/1000' | bc -l)
    echo $R

    One drawback: it has no rounding, only truncation, so you'd have to
    improvise with +0.5 or use printf.
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From BIG Umberto@3:770/3 to zeneca on Wed Oct 6 15:52:17 2021
    In date: Wed, 06 Oct 2021 17:28:53 on group: comp.sys.raspberry-pi,
    zeneca wrote:

    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765

    let NUM=$TOT/1000

    (( NUU=$TOT/1000))

    echo "$TOT $NUM $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance

    Bash use ONLY INTEGER numbers!

    Read man bash!
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Andy Burns@3:770/3 to zeneca on Wed Oct 6 16:56:37 2021
    zeneca wrote:

    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765
    let NUM=$TOT/1000
    (( NUU=$TOT/1000))
    echo "$TOT $NUM  $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance


    TOT=21765
    NUM=`echo $TOT / 1000 |bc -l`
    echo "$TOT $NUM"


    But don't be fooled, $NUM is a string, not a floating point number
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Lew Pitcher@3:770/3 to The Natural Philosopher on Wed Oct 6 17:48:15 2021
    On Wed, 06 Oct 2021 18:29:42 +0100, The Natural Philosopher wrote:

    On 06/10/2021 16:56, Andy Burns wrote:
    zeneca wrote:

    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765
    let NUM=$TOT/1000
    (( NUU=$TOT/1000))
    echo "$TOT $NUM  $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance


    TOT=21765
    NUM=`echo $TOT / 1000 |bc -l`
    echo "$TOT $NUM"


    But don't be fooled, $NUM is a string, not a floating point number
    In Javascript and many other languages, there is no difference.

    Irrelevant. The topic of this conversation is Bash, not javascript
    nor "many other languages".

    Your digression seems meant only to confuse the issue under discussion.


    --
    Lew Pitcher
    "In Skills, We Trust"
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Richard Kettlewell@3:770/3 to Lew Pitcher on Wed Oct 6 19:10:57 2021
    Lew Pitcher <lew.pitcher@digitalfreehold.ca> writes:
    The Natural Philosopher wrote:
    On 06/10/2021 16:56, Andy Burns wrote:
    But don't be fooled, $NUM is a string, not a floating point number
    In Javascript and many other languages, there is no difference.

    Irrelevant. The topic of this conversation is Bash, not javascript
    nor "many other languages".

    Your digression seems meant only to confuse the issue under discussion.

    Also it’s wrong. Strings and numbers are distinct types in JS.

    > typeof("")
    "string"
    > typeof(0)
    "number"

    https://262.ecma-international.org/12.0/#sec-ecmascript-language-types

    --
    https://www.greenend.org.uk/rjk/
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From The Natural Philosopher@3:770/3 to Andy Burns on Wed Oct 6 18:29:42 2021
    On 06/10/2021 16:56, Andy Burns wrote:
    zeneca wrote:

    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765
    let NUM=$TOT/1000
    (( NUU=$TOT/1000))
    echo "$TOT $NUM  $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance


    TOT=21765
    NUM=`echo $TOT / 1000 |bc -l`
    echo "$TOT $NUM"


    But don't be fooled, $NUM is a string, not a floating point number
    In Javascript and many other languages, there is no difference.

    --
    Truth welcomes investigation because truth knows investigation will lead
    to converts. It is deception that uses all the other techniques.
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Jean-Pierre Kuypers@3:770/3 to pasIci@ailleur.fr on Wed Oct 6 20:13:31 2021
    In article (Dans l'article) <sjkfbl$985$1@gioia.aioe.org>, zeneca <pasIci@ailleur.fr> wrote (écrivait) :

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance

    Faut vraiment être de France pour oser poster dans la langue de
    Voltaire.

    Va donc voir sur fr.comp.sys.raspberry-pi

    --
    Jean-Pierre Kuypers
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Andy Burns@3:770/3 to The Natural Philosopher on Wed Oct 6 19:22:08 2021
    The Natural Philosopher wrote:

    Andy Burns wrote:

    But don't be fooled, $NUM is a string, not a floating point number

    In Javascript and many other languages, there is no difference.

    They are typed, but it's weak rather than strong, and has automatic promotion

    str = "1.570795";
    num = 1.570795;
    res = 2 * str;
    alert([typeof(str), typeof(num), res, typeof(res)]);

    <https://jsfiddle.net/useo63xy/1/>
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From zeneca@3:770/3 to All on Thu Oct 7 09:37:41 2021
    Le 06/10/2021 à 17:28, zeneca a écrit :
    Hello

    ennuient mais??

    #/bin/bash

    TOT=21765

    let NUM=$TOT/1000

    (( NUU=$TOT/1000))

    echo "$TOT $NUM  $NUU"

    le resulta est 21

    Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
    Merci d'avance
    merci à tous.
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Anton Shepelev@3:770/3 to All on Mon Oct 11 10:22:21 2021
    A. Dumas:

    Yes. You can install 'bc' to do more math in scripts, for
    example:

    R=$(echo 'scale=3;21765/1000' | bc -l)
    echo $R

    One drawback: it has no rounding, only truncation, so
    you'd have to improvise with +0.5 or use printf.

    Or you can keep truncation, but set up one extra digit of
    precision...

    --
    () ascii ribbon campaign - against html e-mail
    /\ http://preview.tinyurl.com/qcy6mjc [archived]
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)
  • From Pancho@3:770/3 to Anton Shepelev on Mon Oct 11 21:46:24 2021
    On 11/10/2021 08:22, Anton Shepelev wrote:
    A. Dumas:

    Yes. You can install 'bc' to do more math in scripts, for
    example:

    R=$(echo 'scale=3;21765/1000' | bc -l)
    echo $R

    One drawback: it has no rounding, only truncation, so
    you'd have to improvise with +0.5 or use printf.

    Or you can keep truncation, but set up one extra digit of
    precision...

    How does that help?

    echo 'scale=4;1/3*3' | bc -l
    --- SoupGate-Win32 v1.05
    * Origin: Agency HUB, Dunedin - New Zealand | Fido<>Usenet Gateway (3:770/3)