# Omit zeros before the decimal point and convert scientific notation in siunitx/pgfmath

I'm trying to automatically format numbers in a way that doesn't convert say .8 to 0.8 while at the same time scientific notation is converted to exponent-free notation. siunitx seems to be able to do both but I don't get it to work together.

\documentclass{article}
\usepackage{siunitx}
\pagestyle{empty}
\begin{document}
\myround{.8}
\myround{1}
\myround{4.00000000001}
\myround{-.1151}
\myround{4.44089209850063E-16}

.80
1
4
-.12
0
\end{document}


The first \newcommand in this MWE IMHO should produce the right result because it got all the right options. However, the zeros before the decimal point are added back in:

Using the second macro definition (that is commented out) yields this result, proving that in principle it should work but of course the scientific notation isn't converted and not rounded properly either (rounding to two decimal places, 4.44×10-16 should be 0.00×100 if anything).

I also added the pgfmath tag because \pgfmathprintnumber seems to have much of the same options as \num from siunitx and I don't know if one uses the other internally and I also wouldn't mind to use that other if it does what I need.

-
Have a look at the numprint package! –  Keks Dose Mar 12 '13 at 17:14
The scientific notation doesn’t allow .80 (or 0.80 for that matter). PGF’s math printing number and siunitx are independent (though you can send siunitx’ settings to PGF). –  Qrrbrbirlbel Mar 12 '13 at 17:19
@Jake Sorry I didn't make that clear: the second line is the desired output. –  Christian Mar 12 '13 at 17:20
@Qrrbrbirlbel Good to know. The thing is, I don't want scientific notation but I occasionally get it on the input side and to get rid of it I need those options. –  Christian Mar 12 '13 at 17:24
The current siunitx code works such that the two operations here are entirely separate. Forcing a fixed exponent is set up such that the output must have an integer part even if it's zero. I can of course look to alter this behaviour: the problem is getting the 'expected' interactions correct. –  Joseph Wright Mar 13 '13 at 9:01

\pgfmathprintnumber can do this if you specify skip 0. and fixed:

\documentclass{article}
\usepackage{tikz}
\newcommand{\myround}[1]{\pgfmathprintnumber[skip 0.,fixed]{#1}}
\pagestyle{empty}
\begin{document}
\myround{.8}
\myround{1}
\myround{4.00000000001}
\myround{-.1151}
\myround{4.44089209850063E-16}

.80
1
4
-.12
0
\end{document}

-
This is almost perfect, thanks! If you know a way to set the numbers in the surrounding font instead of always in math font, that would be perfect. If not I have to change the parts where I still have to use siunitx because I use actual units and go through my document if I somewhere still use numbers without any surrounding macro. –  Christian Mar 12 '13 at 19:09
@Christian: No, sorry, I don't know how to do that off the top of my head. It's probably best if you open a new question for this along with an example document. –  Jake Mar 12 '13 at 22:38
I guess just fixing my document is easier. I forgot to mention that I did find assume math mode=true which switches off ensuremath but that doesn't seem like the right way accomplish that. Anyway, as I said, this will do just fine. Thanks! –  Christian Mar 12 '13 at 22:48