3
$\begingroup$

I am getting an unexpected result with NumberForm's NumberPadding option when specifying NumberSigns formatting option.

NumberForm[-60., {3, 1}, NumberPadding -> {" ", "0"}, NumberSigns -> {{"(", ")"}, ""}]
(* (60.)0 *)

The above gives (60.)0 when (60.0) is expected. Have I missed something in my expectation? How do I specify the format with NumberForm (or any of the other *Form functions so that it works with both positive and negative numbers with padding?

That is, -60. would give (60.0) and 60. would give 60.0 (leading and trailing space after padding for {3,1}).

$\endgroup$
  • 1
    $\begingroup$ Oh, I see it. Just saw the solution with the help of @Mr.Wizard post after I typed the edit. I need NumberSigns -> {{"(", ")"}, {" ", " "}} along with SignPadding -> True from @Mr.Wizard post. $\endgroup$ – Edmund Jul 20 '16 at 19:23
  • $\begingroup$ I am glad you solved your problem and that I was able to point you in the right direction. $\endgroup$ – Mr.Wizard Jul 20 '16 at 19:26
4
$\begingroup$

I think you need the SignPadding option:

NumberForm[-60., {3, 1}, NumberPadding -> {" ", "0"}, 
 NumberSigns -> {{"(", ")"}, ""}, SignPadding -> True]
(60.0)
$\endgroup$
  • $\begingroup$ Close except that positive numbers come out with an extra 0; 60.00 . The SignPadding does get it correct for negatives but not positives. I am looking for (60.0) and `` 60.0 `` (leading and trailing space) for -60. and 60.. Perhaps I need to be clearer in the post. (+1) $\endgroup$ – Edmund Jul 20 '16 at 19:17
  • $\begingroup$ I just saw the solution when typing the edit. Your SignPadding addition was crucial. $\endgroup$ – Edmund Jul 20 '16 at 19:24

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.