Skip to content

"%6.6d" etc do work the same as in C  #3

Description

@goodluck1982
#include <stdio.h>
int main()
{
  printf("%6.6d\n",3);
  printf("%6.3d\n",3);
  printf("%-6.3d\n",3);
  printf("%+6.3d\n",3);
  printf("%-+6.3d\n",3);
  return(0);
}

The above C code gives the follwing results:

000003
   003
003   
  +003
+003

While the package "sprintf`" gives the follwing results which are different from those of C.

In[2]:= sprintf["%6.6d",3]
Out[2]=      3
In[3]:= sprintf["%6.3d",3]
Out[3]=      3
In[4]:= sprintf["%-6.3d",3]
Out[4]= 3     
In[5]:= sprintf["%+6.3d",3]                  
Out[5]=     +3
In[6]:= sprintf["%-+6.3d",3]
Out[6]= +3 

Metadata

Metadata

Assignees

No one assigned

    Labels

    bugSomething isn't working

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions