Removing trailing zeroes

So, I can't figure out how to do a previous question with printf, so I'm taking a different approach. Suppose I have a set of numbers:

1200,135.000000,12.30100,3212.3200,1.759403,,1230,101.101010,100.000000

I want to remove all trailing zeroes after the decimal, and, if it ends up orphaned, the decimal itself. That last bit's not so important; if just the trailing zeroes can be removed, I'm certain I can kill off orphaned decimals. My various attempts are, at best, weak partial solutions. I can remove trailing zeroes and a few other tricks, but all fall short. The only guarantees about the incoming data are 1) the first field will always be a positive integer and no field will have more than 6 digits after the decimal.

So, how in the world can I remove from each field (except the first, to which this need not apply) any trailing zeroes after the decimal? For what it's worth, after digging through the forum, I've found no working solutions. A method (gsub? looping gsub? idunno...) that works would give as output for the above line:

1200,135,12.301,3212.32,1.759403,,1230,101.101010,100
$ echo 1200,135.000000,12.30100,3212.3200,1.759403,,1230,101.101010,100.000000 | sed "s/\.0\{1,\}//g"
1200,135,12.30100,3212.3200,1.759403,,1230,101.101010,100

If at all possible, I'd like to do this within an awk script, although I don't object to a system call in a pinch. Also, when I run your solution, I get:

# echo 1200,135.000000,12.30100,3212.3200,1.759403,1230,101.101010,100.000000 | sed "s/\.0\{1,\}//g"
1200,135,12.30100,3212.3200,1.759403,1230,101.101010,100

instead of:

1200,135,12.301,3212.32,1.759403,1230,101.101010,100

Do you get the same on your system, or does it work there?

FWIW, the most promising (but still failed...) solution I can think of is to put a trailing comma on $0, and then apply up to 5 times something like:

gsub("0,",",",$0)

Unfortunately, that only works if there's a way to apply it only to those fields which contain a decimal point. The fact that this is a gsub applying to $0 makes that difficult, and the solution as written would turn, for example, 1200 into 120, then into 12 on a second application.

 cat abc.txt
1200
135.000000
12.30100
3212.3200
1.759403
1230
101.101010
100.000000

awk '{ if ($0 ~ /\./){ sub("0*$","",$0); sub ("\.$","",$0);} print}' abc.txt

1200
135
12.301
3212.32
1.759403
1230
101.10101
100

HTH,
PL

$ echo 1200,135.000000,12.30100,3212.3200,1.759403,1230,101.101010,100.000000 | awk -F"," -v OFS="," ' { for(i=0;NF-i++;){sub("[.]*0+ *$","",$i)};$1=$1 }1 '
12,135,12.301,3212.32,1.759403,123,101.10101,100

---------- Post updated at 10:51 PM ---------- Previous update was at 10:45 PM ----------

My sed and datpal's awk solution fail in this case

$ echo 1200.00200300 | sed "s/\.0\{1,\}//g"
1200200300
$ echo 1200.00200300 | awk '{ if ($0 ~ /\./){ sub("0*$","",$0); sub ("\.$","",$0);} print}'
1200.00200
$ echo 1200.00200300 | awk -F"," -v OFS="," ' { for(i=0;NF- i++;){sub("[.]*0+ *$","",$i)};$1=$1 }1 '
1200.002003

It works fine for me anbu23

 echo 1200.00200300 | awk '{ if ($0 ~ /\./){ sub("0*$","",$0); sub ("\.$","",$0);} print}'
1200.002003

In fact what u gave will break for whole numbers

 echo 100 | awk -F"," -v OFS="," ' { for(i=0;NF- i++;){sub("[.]*0+ *$","",$i)};$1=$1 }1 '
1

I added a slash and it worked for me

$ echo 1200.00200300 | awk '{ if ($0 ~ /\./){ sub("0*$","",$0); sub ("\\.$","",$0);} print}'
1200.002003

You are right. My code will break for whole numbers. Here is the fixed code

echo 1200,135.000000,12.30100,3212.3200,1.759403,1230,101.101010,100.000000 | awk -F"," -v OFS="," ' { for(i=0;NF-i++;){ if($i ~ /[.]/){ sub("[.]*0+ *$","",$i) }}$1=$1}1'
1200,135,12.301,3212.32,1.759403,1230,101.10101,100

Will this work for you ?

awk 'BEGIN{FS=OFS=","}{for(i=1;++i<=NF;)$i=int($i)}1'

Does that work on your system? I suppose I might have a different version of awk. It appears to chop off everything up to the decimal place, at least on my system:

# echo 1200,135.000000,12.30100,3212.3200,1.759403,1230,101.101010,100.000000 | awk 'BEGIN{FS=OFS=","}{for(i=1;++i<=NF;)$i=int($i)}1'
1200,135,12,3212,1,1230,101,100

It appears that anbu23's solution works well. It makes sense, even, except that I don't understand a couple of minor things. Here's where my dampness behind the ears shows through, I'm afraid...

awk -F"," -v OFS="," ' { for(i=0;NF-i++;){ if($i ~ /[.]/){ sub("[.]*0+ *$","",$i) }}$1=$1}1'

I don't understand the purpose of the $1=$1 and the 1. They appear critical, but what do they do? Many thanks for the solutions offered. They serve well to show me where I can focus my learning.