Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I would like to display numbers like 9.0001 and 10.0001 in the fixed-width form of xx.xxxx. This seems like a perfect job for:

NumberForm[#, {6, 4}, NumberPadding -> {"0", "0"}] & /@ {9.0001, 10.0001}

But this returns {009.0001, 010.0001}, which has one extra leading zero.

Reducing the number of digits doesn't fix this.

NumberForm[#, {5, 4}, NumberPadding -> {"0", "0"}] & /@ {9.0001, 10.0001}

{09.0001,010.0000}

Why is at least one copy of the left NumberPadding always being added, even when this makes the total number of digits exceed n, the desired total number of digits?

share|improve this question
    
@MikeHoneychurch, thanks for the reminder. While your answer contains a good solution to the problem, m_goldberg's answers the exact question. –  ArgentoSapiens May 20 at 11:48

1 Answer 1

up vote 1 down vote accepted

I think Mathematica is padding one extra position on the left to preserve space for a possible minus sign.

NumberForm[#, {6, 4}, NumberPadding -> {"*", "0"}] & /@ 
  {1234.567, -1234.567, 12.34567, -12.34567, 1.234567, -1.234567}
 {*1234.5700, -1234.5700, *12.3457, -12.3457, **1.2346, *-1.2346}
share|improve this answer

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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