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!
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
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
On 06/10/2021 16:56, Andy Burns wrote:
zeneca wrote:In Javascript and many other languages, there is no difference.
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
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 numberIn 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.
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 numberIn Javascript and many other languages, there is no difference.
Ok mais j'aimerai 21.765 ou 21.7 Qq chose comme ça
Merci d'avance
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.
Hellomerci à tous.
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
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.
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...
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 418 |
Nodes: | 16 (2 / 14) |
Uptime: | 23:01:32 |
Calls: | 8,804 |
Calls today: | 2 |
Files: | 13,304 |
Messages: | 5,970,093 |