简体   繁体   中英

String Format in Progress does not suppress numbers

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

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.

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.

To avoid TRIM use STRING() or SUBSTITUTE() like so:

display
  "[" + string( 13, ">>9" ) + "]" skip
  "[" + string( 13, "ZZ9" ) + "]" skip
  "[" + string( 13 ) + "]"        skip
  "[" + substitute( "The number &1 without extra padding", 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). I like SUBSTITUTE() because it behaves well with "unknown" values and in a lot of cases where you don't want padding you are probably building a parameterized string anyway.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM