# Is there a number format that omits redundant decimal points?

Mathematica has several number formats such as ScientificForm, EngineeringForm, etc. Are there any that can be configured to omit a redundant decimal point, or alternatively: work on exact numbers?

I want either

myForm[2.*10^10]


$2\times 10^{10}$

or

myForm[2*10^10]


$2\times 10^{10}$

(Of course for 2.5*10^10 the decimal point would be required.)

With ScientificForm, I get

ScientificForm[2.*10^10]


$2.\times 10^{10}$

ScientificForm[2*10^10]


$20000000000$

I can piece the result together with strings or HoldForm, but my question is: is there a builtin solution?

Why do I think there may be a builtin way? Because of the tick marks here:

Graphics[{Circle[{0, 0}, 10^10]}, Frame -> True]


It is however possible that this formatting is done by the front end and isn't available in the kernel.

What is this needed for? Precisely for tick labels. I know that a reasonable workaround for this application is using $2.0\times 10^{10}$, and I have been using that in the past. This time I want simply $2$ instead of $2.0$ or $2.$.

You may use the NumberFormat option of ScientificForm.

With

nf = With[{m = ToExpression@#1},
Row[{If[PossibleZeroQ[m - Round[m]], ToString@Round[m], #1],
Sequence @@ If[#3 == "", {}, {"×", #2^#3}]}]] &


The arguments to NumberFormat are strings so you have to convert to test.

Then

v = {2.*10^10, 2.000001, 6885.45559^2};
ScientificForm[v, NumberFormat -> nf]


Hope this helps.

# Update

Using StringTrim from comments and also added spacing.

nf = Row[{StringTrim[#1, "."],
Sequence @@ If[#3 == "", {}, {Spacer[3], "×", Spacer[3], #2^#3}]}] &

ScientificForm[v, NumberFormat -> nf]


• Could we simplify this to simply Row[{StringTrim[#1, "."], "\[Times]", Superscript[#2, #3]}] &? A problem both with this and with your solution is that the spacing around the operator $\times$ isn't correct. Commented Sep 28, 2016 at 11:42
• @Szabolcs That does not work for numbers like 2.0001. You end up with 2x10. Commented Sep 28, 2016 at 12:33
• @Szabolcs See update for spacing and using StringTrim. Commented Sep 28, 2016 at 12:41