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 bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Basic Question - "%5.2f" ??

Status
Not open for further replies.

DonP

IS-IT--Management
Jul 20, 2000
684
US
Just a very basic question that I am embarrassed to ask but will anyway. What does &quot;%5.2f&quot; mean, as in:<br><br>printf DATAFILE (&quot;%5.2f&quot;,$Value);<br><br>It appears to be printing a space, but removing it gives a server error. I want to stop the space from being printed to the datafile, which is a flat database because it causes some minor import problems into my database application. This is a Linux server in case that makes a difference.<br><br>Thanks!<br>Don
 
It's been a while, but, if memory serves......<br><br>assuming $Value contains a numeric....<br>&quot;%5.2f&quot; tells printf to used a fixed format of 5 chars, dot, 2 chars.&nbsp;&nbsp;I believe it simply<br>truncates any trailing digits.&nbsp;&nbsp; <p> <br><a href=mailto: > </a><br><a href= > </a><br> keep the rudder amid ship and beware the odd typo
 
Thanks!&nbsp;&nbsp;Then my blank space must be coming from somewhere else, which I should be able to find knowing it is not the %5.2f. (Yes, $Value is numeric variable being calculated elsewhere in the script )<br><br>Don
 
It was easy, assuming I did it the way it should have been done.&nbsp;&nbsp;Based on what goboating told me, I just made a simple substitution from:<br><br>printf DATAFILE (&quot;%5.2f&quot;,$Value);<br><br>to<br><br>printf DATAFILE (&quot;%1.2f&quot;,$Value);<br><br>Before, it was only printing the extra space when $Value was 0.00 to 9.99.&nbsp;&nbsp;Once it grew to 10.00 or over, there was no space.&nbsp;&nbsp;Now there is no spaces regardless.<br><br>Thanks!<br><br>Don
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top