0
$\begingroup$

I have CountryData coming in via e.g.

Entity["Country", "Australia"][
  EntityProperty["Country", "GDP",
   {"CurrencyUnit" -> "Constant2000USDollar", 
    "TimeSeriesOperator" -> "AnnualGrowthRate"}
  ]
]

Which returns

-0.00383656% per year (* unit: percent per year *)

My desired output is -0.0000383656 (i.e. as purely a decimal number).

I am surprised by how hard it has been to find an answer. Despite this question being very simple, I can't find a way with Quantity, NumberForm, etc.

$\endgroup$
10
  • 5
    $\begingroup$ I'd just do QuantityMagnitude[r]/100 where r is your result you obtained from that long command. !Mathematica graphics -0.0000383656 $\endgroup$
    – Nasser
    Commented Nov 28, 2022 at 9:43
  • 1
    $\begingroup$ Simply take the first part of your result: yourresult[[1]] $\endgroup$ Commented Nov 28, 2022 at 10:08
  • 1
    $\begingroup$ Every object in MMA is like an array. With obi[[0]] you can get the head and with obi[[i,j..] all the parts. Note, this does not work for atomic objects , they consist of only the head. $\endgroup$ Commented Nov 28, 2022 at 12:43
  • 1
    $\begingroup$ Also with FullForm you can see the structure of the returnvalue: FullForm[r] gives you Quantity[-0.0038365585665900404`,Times["Percent",Power["Years",-1]]] $\endgroup$
    – Mathias
    Commented Nov 28, 2022 at 17:32
  • 1
    $\begingroup$ FullForm, TreeForm and ExpressionTree might lead to expressions that are too lengthy at times in which case you can consider InputForm after getting familiar with outputs of FullForm $\endgroup$ Commented Nov 29, 2022 at 2:29

1 Answer 1

2
$\begingroup$

Collection of answers in the comments (many thanks to those commenters):

  1. QuantityMagnitude[%]
  2. %[[1]] or Part[%, 1]

And inspect the output with FullForm[%], TreeForm[%], and ExpressionTree[%].

$\endgroup$

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