Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations gkittelson on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

sprintf to remove 0 right of decimal 1

Status
Not open for further replies.

chirpyform

Programmer
Jun 20, 2003
202
FR
Hi,
I would like to know if there exists an option with sprintf which gets rid of the insignificant zeros right of the decimal point.

At the moment I have :

print curKey,sprintf("%-6.6f",Sum[curKey])

but unfortunately that gives what I want left of the decimal point but always 6 numbers right of the decimal point.
I saw that there is an option 'g' but I can't get it to work.

It is extremely important .....

Thanks

Chris
 
It seems like there should be a simpler way of doing it, but this is the only way I can see.

a=sprintf("%f",Sum[curKey])
sub(/0*$/,"",a)
print curKey,a



CaKiwi
 
sed -e 's/0*[0]$//'
awk & perl should be able to do it in very similar way

don't forget, RTFMP :) guggach
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top