division par 1000 en bash

Do you have a question? Post it now! No Registration Necessary

Translate This Thread From English to

Threaded View
Hello

ennuient mais??

#/bin/bash

TOT21%765

let NUM=$TOT/1000

(( NUU=$TOT/1000))

echo "$TOT $NUM  $NUU"

le resulta est 21


Merci d'avance

Re: division par 1000 en bash
In date: Wed, 06 Oct 2021 17:28:53 on group: comp.sys.raspberry-pi,
zeneca wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

Bash use ONLY INTEGER numbers!

Read  man bash!

Re: division par 1000 en bash
Quoted text here. Click to load it

Quoted text here. Click to load it

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.

Re: division par 1000 en bash
A. Dumas:

Quoted text here. Click to load it

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]

Re: division par 1000 en bash
On 11/10/2021 08:22, Anton Shepelev wrote:
Quoted text here. Click to load it
How does that help?

echo 'scale=4;1/3*3' | bc -l

Re: division par 1000 en bash
zeneca wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it


TOT21%765
NUM=`echo $TOT / 1000 |bc -l`
echo "$TOT $NUM"


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

Re: division par 1000 en bash
On 06/10/2021 16:56, Andy Burns wrote:
Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it
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.

Re: division par 1000 en bash
On Wed, 06 Oct 2021 18:29:42 +0100, The Natural Philosopher wrote:

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it

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"

Re: division par 1000 en bash
Quoted text here. Click to load it

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/

Re: division par 1000 en bash
The Natural Philosopher wrote:

Quoted text here. Click to load it

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/


Re: division par 1000 en bash



Quoted text here. Click to load it


Voltaire.

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

--  
Jean-Pierre Kuypers

Re: division par 1000 en bash

Quoted text here. Click to load it

Quoted text here. Click to load it

Quoted text here. Click to load it


Site Timeline