jgarcia2002
Programmer
Hi All
Need a little help with formating a number that needs to be written to a file. The vendor requires that numbers be formatted as follows -000000000000.00. if the number is positive then a zero should be displayed instead of + so if the above was positive it would be 000000000000.00.
My snippet of code is as follows:
if ($k == $sumIdx)
{
$summaryRec = $summaryRec .$prevRec[$k];
}
else
{
if ($k == 3)
{
$tmpFormatNum = sprintf("%.2f",$prevRec[$k]);
$tmpFormatStr = sprintf("%015d",$tmpFormatNum);
$summaryRec = $summaryRec .$tmpFormatStr;
}
else
{
$summaryRec = $summaryRec .$prevRec[$k]. ",";
}
With the above the second sprintf drops the decimal places. So if I have 82.33 I get 000000000000082 instead of 000000000082.33.
I tried several different format statement to no avail. I was thinking of writing several lines of code to read the value one byte at a time. But I would rather user the format function instead. Any help would be greatly appreciated.
Thanks
Jose'
Need a little help with formating a number that needs to be written to a file. The vendor requires that numbers be formatted as follows -000000000000.00. if the number is positive then a zero should be displayed instead of + so if the above was positive it would be 000000000000.00.
My snippet of code is as follows:
if ($k == $sumIdx)
{
$summaryRec = $summaryRec .$prevRec[$k];
}
else
{
if ($k == 3)
{
$tmpFormatNum = sprintf("%.2f",$prevRec[$k]);
$tmpFormatStr = sprintf("%015d",$tmpFormatNum);
$summaryRec = $summaryRec .$tmpFormatStr;
}
else
{
$summaryRec = $summaryRec .$prevRec[$k]. ",";
}
With the above the second sprintf drops the decimal places. So if I have 82.33 I get 000000000000082 instead of 000000000082.33.
I tried several different format statement to no avail. I was thinking of writing several lines of code to read the value one byte at a time. But I would rather user the format function instead. Any help would be greatly appreciated.
Thanks
Jose'