$n =~ s/\.?0+$//; Update:
Thanks to dreadpiratepeter for spotting my stupid mistake.
The better option would be
$n =~ s/\.\d*?0+$//; Update2:
That worked with my test data but only because I wasn't using formatted strings so trailing 0s were already dealt with. Doh!
With a %x.yf formatted string the original approach will work fine.
jmcnamara came up with probably the best solution Re: Eliminating Trailing Zeros