: !/bin/sh awk ' # needed because of rounding bug in awk (see tround1 script) function mround2(cst) { if ( match(cst,"\...5$") > 0 ) cst += 0.001 return sprintf("%0.2f", cst) } function mround4(cst) { if ( match(cst,"\.....5$") > 0 ) cst += 0.00001 return sprintf("%0.4f", cst) } BEGIN { totalcost = 12.345 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" print "-------" totalcost = 12.345432 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" print "-------" totalcost = 112.345 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" print "-------" totalcost = 112.346 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" print "-------" totalcost = 139.785 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" csvstr = sprintf("fix %0.2f", mround2(totalcost)) print "csvstr=[" csvstr "]" print "-------" totalcost = 2139.799 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.2f", totalcost) print "csvstr=[" csvstr "]" csvstr = sprintf("fix %0.2f", mround2(totalcost)) print "csvstr=[" csvstr "]" print "-------" totalcost = 1234.56785 print "totalcost = " sprintf("%0.5f", totalcost) csvstr = sprintf("%0.4f", totalcost) print "csvstr=[" csvstr "]" csvstr = sprintf("fix %0.4f", mround4(totalcost)) print "csvstr=[" csvstr "]" print "-------" exit 0 } '