4
$\begingroup$

I have this output:

(323909701210368 Sqrt[3] t^(56/3))/(11 Gamma[2/3] Gamma[59/3]) + (
 23266815064996478976000 t^(71/3))/(Gamma[2/3] Gamma[74/3])

I want to have numbers just with 3 digits. For example:

(323 Sqrt[3] t^(56/3))/(11 Gamma[2/3] Gamma[59/3]) + (
 232 t^(71/3))/(Gamma[2/3] Gamma[74/3])

Any suggestion?

$\endgroup$
8
$\begingroup$

A truly weird question! I cant imagine why you would want to do that but here goes..

f[i_] := FromDigits[IntegerDigits[i][[;; 3]]];
((323909701210368 Sqrt[3] t^(56/3))/(11 Gamma[2/3] Gamma[
       59/3]) + (23266815064996478976000 t^(71/3))/(Gamma[2/3] Gamma[
       74/3])) /. 
 {Rational[x_Integer /; x > 1000, y_] :> f[x]/y, x_Integer /; x > 1000 :> f[x]}

(323*Sqrt[3]*t^(56/3))/(11*Gamma[2/3]*Gamma[59/3]) + (232*t^(71/3))/(Gamma[2/3]*Gamma[74/3])

$\endgroup$
2
  • 2
    $\begingroup$ maybe x>999 instead of x>1000? $\endgroup$ – AccidentalFourierTransform Mar 29 '16 at 17:12
  • $\begingroup$ Many many thanks. $\endgroup$ – user37694 Mar 29 '16 at 20:32
9
$\begingroup$

This goes and modifies the displayed box form. Please note that this is not meant to be used as input to other computations, just for display - so it's similar to MatrixForm in that sense.

ClearAll[ShortIntegerForm];

ShortIntegerForm[expr_] := 
 ToBoxes@expr /. 
   n_String /; 
     StringMatchQ[n, Repeated[DigitCharacter, {4, \[Infinity]}]] :> 
    Tooltip[StringJoin[StringTake[n, 3], 
      "\[InvisibleSpace]\[Ellipsis]"], ToExpression@n] // DisplayForm

Now you can apply this form to your expression:

(323909701210368 Sqrt[3] t^(56/3))/(11 Gamma[2/3] Gamma[
      59/3]) + (23266815064996478976000 t^(71/3))/(Gamma[2/3] Gamma[
      74/3]) // ShortIntegerForm

enter image description here

As an added bonus, Tooltip shows the full value if you take your mouse pointer over the short form.

$\endgroup$

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.