6
$\begingroup$

How can I convert the number -0.000007 to a string -0.000007?

I tried:

x = -0.000007;
ToString[x]

That gives an exponential output.

ToString[AccountingForm[N[x, 10], {10, 6}]]

gives the value without sign and parentheses around

(0.000007)
$\endgroup$
2

1 Answer 1

5
$\begingroup$
x = -0.000007;

str = ToString @ AccountingForm[x, {12, 10}, NumberSigns -> {"-", ""}];

str // FullForm

"-0.000007"

ToExpression[str] + 1

0.999993

$\endgroup$
2
  • $\begingroup$ Thank you for the solution. When I evaluate str // FullForm I get: AccountingForm[-7.`*^-6,List[12,6],Rule[NumberSigns,List["-",""]]] $\endgroup$
    – lio
    Commented Jul 14, 2017 at 15:52
  • $\begingroup$ I made a copy mistake, see updated answer with ToString $\endgroup$
    – eldo
    Commented Jul 14, 2017 at 15:58

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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