[pstricks] Suggestions for \psPrintValue
Buddy Ledger
buddyledger at gmail.com
Fri Apr 24 05:58:57 CEST 2009
Herbert,
I have been playing with \psPrintValue and I've found that it does not
round values it truncates. The code below rounds properly. I've also
included an option to display numbers in scientific notation.
Buddy
\documentclass[]{article}
\usepackage{pst-all}
\usepackage{pst-func}
\usepackage{pstricks-add}
\makeatletter
\define at key[psset]{pst-func}{Scin}[0]{\def\psk at Scin{#1}}
\psset[pst-func]{Scin=0}
\def\psPrintValueNew{\pst at object{psPrintValueNew}}
\def\psPrintValueNew at i#1{%
\begin at SpecialObj
\addto at pscode{
/mfont {\psk at PSfont findfont \psk at fontscale scalefont setfont} bind def
/s1 {/Symbol findfont \psk at fontscale scalefont setfont} bind def
\psk at Scin 0 0 gt {%
#1 0 ne {#1 log floor cvi /expon exch def}{/expon 0 def} ifelse
#1 10 expon exp div \psk at decimals -1 gt
{ 10 \psk at decimals exp dup 3 1 roll mul round exch div } if
\psk at decimals 0 eq {cvi} if /numb exch def
expon \psk at valuewidth string cvs /expon exch def
numb \psk at valuewidth string cvs /numb exch def
/txspc \psk at fontscale 4 div def
\psk at xShift\space 0 moveto mfont numb show
txspc 0 rmoveto s1 (\string\264) show
txspc 0 rmoveto mfont (10) show
txspc txspc rmoveto mfont expon show}
{#1 \psk at decimals -1 gt { 10 \psk at decimals exp dup 3 1 roll mul
round %replaced cvi with round
exch div } if
\psk at decimals 0 eq {cvi} if %inserted to handle decimals=0
\psk at valuewidth string cvs /Output exch def
\psk at xShift\space 0 moveto mfont Output show} ifelse
}%
\end at SpecialObj%
}
\makeatother
\begin{document}
Number = 1.63725E+002 \newline
\newline
psPrintValue Output \newline
\psPrintValue[decimals=-1]{1.63725E+002}\newline
\psPrintValue[decimals=0]{1.63725E+002}\newline
\psPrintValue[decimals=1]{1.63725E+002}\newline
\psPrintValue[decimals=2]{1.63725E+002}\newline
\psPrintValue[decimals=3]{1.63725E+002}\newline
psPrintValueNew Output \newline
\psPrintValueNew[decimals=-1]{1.63725E+002}\newline
\psPrintValueNew[decimals=0]{1.63725E+002}\newline
\psPrintValueNew[decimals=1]{1.63725E+002}\newline
\psPrintValueNew[decimals=2]{1.63725E+002}\newline
\psPrintValueNew[decimals=3]{1.63725E+002}\newline
\psPrintValueNew[decimals=-1,Scin=1]{1.63725E+002}\newline
\psPrintValueNew[decimals=0,Scin=1]{1.63725E+002}\newline
\psPrintValueNew[decimals=1,Scin=1]{1.63725E+002}\newline
\psPrintValueNew[decimals=2,Scin=1]{1.63725E+002}\newline
\psPrintValueNew[decimals=3,Scin=1]{1.63725E+002}\newline
\end{document}
More information about the PSTricks
mailing list