why doesnt my script work!!!

Is there a utility or command I can use to tell the number of decimal places a number has. For instance, if the number is 432, it will give hundred as the number of decimal places.

Heedunk, I'm not sure I follow.. in math, there is no "number of decimal places", unless you're talking about two numbers after the decimal, or three numbers before the decimal. I assume you want to display what the largest column is..? As in ten, hundred, or a thousand?

Maybe someone has a better solution, but I think you'll need a case statement... in ksh:

a=432.27
b=${a%%.*}
case ${#b} in
  2) echo "tens" ;;
  3) echo "hundreds" ;;
esac

Returns:
> hundreds

as far as i know there is no utility that displays the mathamatical notation of one, tens, hundreads, thousands....... or its reverse.

thats not to say that there are none. because i am sure there are but by default for a standard OS install there are none. (that i am aware of).

you can easily come up with a script to do it tho. all you would have to do is:

1) validate the string is only numeric.
2) split the string on a decimal.
3) count the number of char. the pre decimal sting is.
4) have some sort fo loop or case statement so for x charicters it is a hundread or a thousand or a billion and so one.

or do something like posted above.

Heedunk, looking at your questions thus far, either you're learning unix on your own and are new at it or you're posting homework assignments. If it's the former, then welcome to the world of unix!

If it's the latter, then the code I put will probably be too advanced to turn into a teacher anyway... follow Norsk's logic to come up with a way.

Because this may be homework, I won't explain this. Note though that in the construct "l(432)", the first character is a letter "l".

echo "a = l(432) / l(10) ; scale=0 ; a = a / 1 ; 10^a" | bc -l

I get an expr syntax error. here is my code

#!/bin/sh
echo 'Enter a number: \c'
read number

echo $number > test #copy value in number to file test

decimal=`wc -m test` #read decimal places for test

answer=`expr $decimal - 1` #remove new line character

case $answer in
1)
echo One
;;
2)
echo Ten
;;
3)
echo Hundred
;;
4)
echo Thousand
;;
5)
echo Ten Hundred
;;
6)
echo Million
;;
7)
echo Ten Million
;;
8)
echo Hunderd Million
;;
*)
error: value exceeds limitations of program
;;
esac

I'd merge them if I could. (Consider it done)

Between these two lines:
decimal=`wc -m test` #read decimal places for test
answer=`expr $decimal - 1` #remove new line character

place:
echo "$decimal"

to see what's really in that variable. I suspect more than you think...

But what I'd really like to know is why you didn't even seem to try the suggestions from the previous post? Was Perderabo correct in his assumption?

------
Thanks, RTM. :slight_smile:

Actually, you should just post the exact error you see on screen .. something more than "i got a syntax error".

echo "Enter number : \c"
read number
Len=`echo $number | awk -F"." '{print $1}' | awk '{print length}'`

case $Len in
1) echo One ;;
2) echo Ten ;;
3) echo Hundred ;;
4) echo Thousand ;;
5) echo Ten Hundred ;;
6) echo Million ;;
7) echo Ten Million ;;
8) echo Hunderd Million ;;
*) error: value exceeds limitations of program ;;
esac