Beefy Boxes and Bandwidth Generously Provided by pair Networks
P is for Practical

Re: DBI Removing Leading Zeroes 0's

by kennethk (Abbot)
on Apr 08, 2013 at 16:25 UTC ( #1027556=note: print w/replies, xml ) Need Help??

in reply to DBI Removing Leading Zeroes 0's

To expound upon Corion's wisdom, you are conflating numerical values and formatting. As far as your database (as well as Perl) is concerned, 0301 and 301 are the same number, but are different strings. Oracle will also truncate trailing zeroes in decimals, because those contain no numerical information.

So the question is do you need to store all four digits, which would suggest you should use perhaps a char(4) type instead, or do you just need to output four digits? Any time you need to control formatting on a numerical output, you should probably turn to printf/sprintf, e.g.

~$ perl -e 'printf "%04d\n", 301' 0301

#11929 First ask yourself `How would I do this without a computer?' Then have the computer do it the same way.

Log In?

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027556]
and all is quiet...

How do I use this? | Other CB clients
Other Users?
Others browsing the Monastery: (3)
As of 2017-12-11 23:25 GMT
Find Nodes?
    Voting Booth?
    What programming language do you hate the most?

    Results (319 votes). Check out past polls.