Help to export decimal to outptu file with trailing zeros

Albert W

New Member
Tried a number of different ways to export trailing zeros but unsuccessful. Please help. Much appreciate.

output to "/tmp/test.txt".
DEFINE VARIABLE var-price AS decimal NO-UNDO.
var-price = 123.1230.
export delimiter "," "bac" var-price format "999999.9999".

Output
"bac",123.123
Problem:
The trailing zero is missing.
 

Cringer

ProgressTalk.com Moderator
Staff member
Code:
output to "c:\temp\test.txt".
DEFINE VARIABLE var-price AS decimal NO-UNDO.
var-price = 123.1230.
put unformatted "bac" "," string(var-price,"999999.9999").

output close.
 

TomBascom

Curmudgeon
Not only is not the question but... what the heck does changing the file name to have "CSV" as an extension have to do with the program's output?

Just for kicks I went ahead and changed it. I always prefer actual testing to "thought exercises". Especially when someone does me the courtesy of providing a nice simple code snippet for my pleasure.

The output still has the zero.

So, clearly, your problem lies elsewhere. My guess is that whatever is reading the "CSV" is not handling the trailing zero in the way that you wish it would.
 

Cringer

ProgressTalk.com Moderator
Staff member
Excel will ignore the trailing zeros if you open a csv. But then that's excel. As you say the output is still the same, it's just Excel taking liberties with your data. Be very wary of opening csv files in Excel as you will end up having many woes.
 

Rob Fitzpatrick

ProgressTalk.com Sponsor
Be very wary of opening csv files in Excel as you will end up having many woes.

As with any application or framework, Excel has its documented behaviours and its bugs. I find the "woes" of many people are simply due to their assumptions of how it should behave being different from how it is designed to behave. Kind of like FOR FIRST table in ABL...
 

Albert W

New Member
Many thanks. I use the idea and make some change to remove the leading zeros and blank spaces so I can the results I was after.

output to "/tmp/test.txt".
DEFINE VARIABLE var-price AS decimal NO-UNDO.
define variable var-char1 as char.
var-price = 0223.1230.
var-char1 = string(var-price, "ZZZZZZ.9999").
put
unformatted "abc", trim(var-char1)

Then I get the output I need:
abc,223.1230
 

Cringer

ProgressTalk.com Moderator
Staff member
If you don't want the leading zeros then use the format ">>>>>9.9999".
 
Top