# dc(1) and leading zeros?



## Carpetsmoker (Jan 7, 2011)

I've got a shell script and I do some calculations with dc(1).

I need to have one number printed with leading zeros; I can't find an easy and straightforward way to do this with dc itself, but the manpage does mention:



> Z
> Pops a value off the stack, calculates the number of digits it has (or number of characters, if it
> is a string)  and  pushes  that number.  The *digit count for a number does not include any leading zeros*, even if those appear to the right of the radix point.



Which sort of implies there is an easy and straightforward way ...

I know there are a zillion-and-one method of accomplishing this, and I the script is running happily with one of them. I'm just curious


----------



## wblock@ (Jan 8, 2011)

The 8-stable man page for dc(1) doesn't have that sentence mentioning leading zeros.  Where are you seeing it?


----------



## Carpetsmoker (Jan 8, 2011)

Fedora Core (Yeah, it's what we use at work. I don't have a lot to say in this matter).

It's both GNU dc, so I sort of assumed it would be the same on FreeBSD ... I just checked and on FreeBSD it's indeed different:


```
Z      Pops  a  value off the stack, calculates the number of digits it
              has (or number of characters, if it is a string) and pushes that
              number.
```


----------

