0

I am working with a function that returns output in AccountingForm format. I would like to do math with that output, but Mathematica does not recognize it as numbers. Is there a way to convert a number in AccountingForm back into a real number?

x1 = 23.3;
x2 = AccountingForm[x1];
2*x2 (* does not compute *)

various things I have tried . . .

2*NumberForm[x2, 2] (* does not compute *)

2*N[x2, 2] (* does not compute *)

2*Apply[Real, x2] (* does not compute *)

2*ToExpression[x2] (* does not compute *)

Thanks

Michael Stern
  • 4,695
  • 1
  • 21
  • 37

1 Answers1

2

You can extract the number from the AccountingForm head, as per PartsOfExpressions (which may address some shortcomings that I'm forgetting to mention), by extracting the first part using any alias for that operation:

x=AccountingForm[3.14];
x=x[[1]]

or x=First@x, or x=Part[x,1]

N.J.Evans
  • 5,093
  • 19
  • 25