Beefy Boxes and Bandwidth Generously Provided by pair Networks
Keep It Simple, Stupid
 
PerlMonks  

Re: DBI Removing Leading Zeroes 0's

by kennethk (Monsignor)
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.


Comment on Re: DBI Removing Leading Zeroes 0's
Select or Download Code

Log In?
Username:
Password:

What's my password?
Create A New User
Node Status?
node history
Node Type: note [id://1027556]
help
Chatterbox?
and the web crawler heard nothing...

How do I use this? | Other CB clients
Other Users?
Others surveying the Monastery: (3)
As of 2014-08-21 02:34 GMT
Sections?
Information?
Find Nodes?
Leftovers?
    Voting Booth?

    The best computer themed movie is:











    Results (127 votes), past polls