division par 1000 en bash

Hello

ennuient mais??

#/bin/bash

TOT=21765

let NUM=$TOT/1000

(( NUU=$TOT/1000))

echo "$TOT $NUM $NUU"

le resulta est 21

Merci d'avance

Reply to
zeneca
Loading thread data ...

Bash use ONLY INTEGER numbers!

Read man bash!

Reply to
BIG Umberto

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

Reply to
Andy Burns

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.

Reply to
A. Dumas

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.
Reply to
The Natural Philosopher

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"
Reply to
Lew Pitcher

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

formatting link

--
https://www.greenend.org.uk/rjk/
Reply to
Richard Kettlewell

In article (Dans l'article) , zeneca

Voltaire.

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

--
Jean-Pierre Kuypers
Reply to
Jean-Pierre Kuypers

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)]);

Reply to
Andy Burns

Reply to
zeneca

A. Dumas:

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]
Reply to
Anton Shepelev

How does that help?

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

Reply to
Pancho

ElectronDepot website is not affiliated with any of the manufacturers or service providers discussed here. All logos and trade names are the property of their respective owners.