good chemistry is complicated,and a little bit messy -LW PerlMonks

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??

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
[download]

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

Create A New User
Node Status?
node history
Node Type: note [id://1027556]
help
Chatterbox?
 [Corion]: Do you want to launch a script and keep the command prompt/console window open? [Corion]: Do you want to wait for a key press before closing the window? [LanX]: I want the command line in the history [tye]: -Mouse [Corion]: Option a) would mean launching cmd.exe /k c:\path\to\ batchfile- launching-perl- script.cmd. Option b) would be to add pause as the last line of said batch file. [LanX]: First day after holidays ... and already stressed by the fact that colleagues changed stuff without communication ... apparently I'm the only one trying to fight entropy [Corion]: LanX: The command is always in the history if you typed it in before. If you didn't type the command into the command line, it will not be there. I think there is doskey which can stuff command lines into the history LanX damns the cult of CB ;-) LanX WTF WTF WTF [LanX]: please forget my last 3 posts

How do I use this? | Other CB clients
Other Users?
Others examining the Monastery: (13)
As of 2017-03-27 15:46 GMT
Sections?
Information?
Find Nodes?
Leftovers?
Voting Booth?
Should Pluto Get Its Planethood Back?

Results (320 votes). Check out past polls.