Home > Enterprise >  String Format in Progress does not suppress numbers
String Format in Progress does not suppress numbers

Time:02-02

For my Job I am currently working with the programming language PROGRESS. To format numbers etc. we are using the simple STRING() function. Now the following problem appeared while developing:

If I have a number like 13 and print it using STRING(13, "Z99") I get " 13" but if I print it using STRING(13, ">99") I still get " 13".

The problem is the blank space. From the Progress documentation it should be possible to erase the blank spaces =>Progress Documentation

As it is defined in the Progress documentation "Z" replaces not available digits with a blank but ">" suppresses the output of the missing digit.

Currently the best solution we have is to use TRIM() around the STRING() function. But as more code goes by I can't stop thinking that this should be possible without the TRIM function.

Or am I misunderstanding the progress documentation?

Thank you guys in advance.

Version: Open Edge 12.2.8

CodePudding user response:

I agree that the documentation on the topic is, at best, confusing.

">" has always replaced missing digits with a SPACE. I can see how the documentation saying that it uses a "blank" is pretty confusing. I suppose that they mean to say "a blank space" or something like that.

Personally I've never actually used "Z". I've looked at it a few times over the years, tested it, and wondered what is supposedly different from ">" since I've not been able to determine that there is a difference. Maybe I should have reported a bug 30 or so years ago? Anyhow, I've never found a use for it.

One option that avoids TRIM would be to use SUBSTITUTE() like so:

display
  "["   string( 13, ">>9" )   "]" skip
  "["   string( 13, "ZZ9" )   "]" skip
  "["   substitute( "&1", 13 )   "]" skip
.

That will result in "export format" being used for the conversion. In other words all significant digits but no commas (or "." if you are using euro format).

CodePudding user response:

Z and > change the behavior of any leading non-format symbol. See:

message quoter( string( 13, '$>>9' ) ).
message quoter( string( 13, '$ZZ9' ) ).

Which will produce output:

" $13"
"$ 13"

Neither of which helps you. The formats are suited for producing fixed width font tabular output.

If you do not need any formatting at all, which is unlikely as soon as your numbers are more than three or so digits, you can use string without a format:

message quoter( string( 13 ) ).

Which produces:

"13"

The quoter function has been used in all the above examples to highlight where the spaces are.

  • Related