Search code examples
stringnumberspostscript

Postscript: how to convert a integer to string?


In postscript , the cvs *operator* is said to convert a number to a string. How should I use it ? I tried :

100 100 moveto
3.14159 cvs show

or

100 100 moveto
3.14159 cvs string show

but it didn't work.

Any help ?


Solution

  • Try 3.14159 20 string cvs show.

    string needs a size and leaves the created string on the stack. cvs needs a value and a string to store the converted value.

    If you're doing lots of string conversions, it may be more efficient to create one string and reuse it in each conversion:

    /s 20 string def
    3.14159 s cvs show